-
Notifications
You must be signed in to change notification settings - Fork 439
Color links as common type #7211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import type { IColorable } from '@/lib/litegraph/src/interfaces' | ||
| import { without } from 'es-toolkit' | ||
|
|
||
| import type { IColorable, ISlotType } from '@/lib/litegraph/src/interfaces' | ||
|
|
||
| /** | ||
| * Converts a plain object to a class instance if it is not already an instance of the class. | ||
|
|
@@ -26,3 +28,31 @@ export function isColorable(obj: unknown): obj is IColorable { | |
| 'getColorOption' in obj | ||
| ) | ||
| } | ||
|
|
||
| export function commonType(...types: ISlotType[]): ISlotType | undefined { | ||
| if (!isStrings(types)) return undefined | ||
|
|
||
| const withoutWildcards = without(types, '*') | ||
| if (withoutWildcards.length === 0) return '*' | ||
|
|
||
| const typeLists: string[][] = withoutWildcards.map((type) => type.split(',')) | ||
|
|
||
| const combinedTypes = intersection(...typeLists) | ||
| if (combinedTypes.length === 0) return undefined | ||
|
|
||
| return combinedTypes.join(',') | ||
| } | ||
|
|
||
| function intersection(...sets: string[][]): string[] { | ||
| const itemCounts: Record<string, number> = {} | ||
| for (const set of sets) | ||
| for (const item of new Set(set)) | ||
| itemCounts[item] = (itemCounts[item] ?? 0) + 1 | ||
| return Object.entries(itemCounts) | ||
| .filter(([, count]) => count === sets.length) | ||
| .map(([key]) => key) | ||
| } | ||
|
|
||
| function isStrings(types: unknown[]): types is string[] { | ||
| return types.every((t) => typeof t === 'string') | ||
| } | ||
|
Comment on lines
+32
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Tighten The core behavior (ignoring Two edge cases are worth tightening/confirming:
Additionally, if any callers ever produce comma‑separated lists with spaces (e.g. If you confirm that 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little conflicted about moving this here, but I think it's good enough.
+ commonType should be in litegraph and should see greater use.
+ Having litegraph reference outside code is bad.
- There's some conflation of litegraph connection types and programming types.
- The function is no longer exported. It's less clear that it's intended as utility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intent is less important than how it's currently being used, so I support this.
If we had something that was serving as a utility and could be put into the frontend utilities package for use here, that would also be good, but YAGNI.