-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[feat]: Scope vueNodesMap per LogicFlow instance to support nested scenarios #2378
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
base: master
Are you sure you want to change the base?
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,4 @@ | ||
| import LogicFlow from '@logicflow/core' | ||
| import LogicFlow, { GraphModel } from '@logicflow/core' | ||
| import { VueNodeView } from './view' | ||
| import { VueNodeModel } from './model' | ||
|
|
||
|
|
@@ -10,13 +10,30 @@ export type VueNodeConfig = { | |
| effect?: (keyof LogicFlow.PropertiesType)[] | ||
| } & Partial<RegisterConfig> | ||
|
|
||
| export const vueNodesMap: Record< | ||
| string, | ||
| { | ||
| component: any | ||
| effect?: (keyof LogicFlow.PropertiesType)[] | ||
| } | ||
| > = {} | ||
| type VueNodeEntry = { | ||
| component: any | ||
| effect?: (keyof LogicFlow.PropertiesType)[] | ||
| } | ||
|
|
||
| // Per-instance map: automatically garbage-collected when the GraphModel is destroyed | ||
| const vueNodesMaps = new WeakMap<GraphModel, Record<string, VueNodeEntry>>() | ||
|
|
||
| /** | ||
| * @deprecated Use {@link getVueNodeConfig} instead for multi-instance support. | ||
| * This global map is still populated for backward compatibility but does NOT | ||
| * isolate registrations across different LogicFlow instances. | ||
| */ | ||
| export const vueNodesMap: Record<string, VueNodeEntry> = {} | ||
|
|
||
| /** | ||
| * Retrieve the Vue node configuration scoped to a specific LogicFlow instance. | ||
| */ | ||
| export function getVueNodeConfig( | ||
| type: string, | ||
| graphModel: GraphModel, | ||
| ): VueNodeEntry | undefined { | ||
| return vueNodesMaps.get(graphModel)?.[type] | ||
| } | ||
|
|
||
| export function register(config: VueNodeConfig, lf: LogicFlow) { | ||
| const { | ||
|
|
@@ -30,10 +47,19 @@ export function register(config: VueNodeConfig, lf: LogicFlow) { | |
| if (!type) { | ||
| throw new Error('You should specify type in config') | ||
| } | ||
| vueNodesMap[type] = { | ||
| component, | ||
| effect, | ||
|
|
||
| const entry: VueNodeEntry = { component, effect } | ||
|
|
||
| // Scope to this LogicFlow instance | ||
| let map = vueNodesMaps.get(lf.graphModel) | ||
| if (!map) { | ||
| map = {} | ||
| vueNodesMaps.set(lf.graphModel, map) | ||
| } | ||
| map[type] = entry | ||
|
Comment on lines
+54
to
+59
|
||
|
|
||
| // Also populate global map for backward compatibility | ||
| vueNodesMap[type] = entry | ||
|
|
||
| lf.register({ | ||
| type, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.