-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,003 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type Atom } from '../../ModelState/State'; | ||
import { ModelState } from '../..'; | ||
|
||
export function merge<ObservableSubjectList extends Array<Atom<any>>>( | ||
streamSource: ObservableSubjectList, | ||
) { | ||
const result = new ModelState<any[]>([]); | ||
|
||
streamSource.forEach((input) => { | ||
input.subscribe((value, extraInfo) => { | ||
result.update(value, extraInfo.concat('combine')); | ||
}); | ||
}); | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
packages/flow/src/Diagrams/Operators/MergeOperator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { type Node } from 'reactflow'; | ||
import { NodeTypeEnum } from '../../Nodes/NodeTypeEnum'; | ||
import { MetaOperator } from '../Operator'; | ||
import { EndPoint, type IMergeOperatorData } from '../types'; | ||
import { type IGenerationOption } from '../../Compiler/graph'; | ||
import { EosCoreSymbol, EosOperatorsSymbol } from '../../Compiler/runtime'; | ||
|
||
export class MergeOperator | ||
extends MetaOperator<IMergeOperatorData> | ||
implements MetaOperator<IMergeOperatorData> | ||
{ | ||
nodeColor?: string | undefined = '#C21292'; | ||
|
||
constructor() { | ||
super({ | ||
operatorName: 'Merge', | ||
operatorType: 'MergeOperator', | ||
nodeType: NodeTypeEnum.Node, | ||
}); | ||
} | ||
|
||
create(): Node<IMergeOperatorData<Record<string, any>>> { | ||
return super.create({ | ||
endPointOptions: { | ||
endPointList: [ | ||
new EndPoint({ | ||
type: 'group', | ||
hint: 'output', | ||
children: [ | ||
new EndPoint({ | ||
label: 'output', | ||
hint: 'output', | ||
variableType: 'array', | ||
type: 'source', | ||
}), | ||
], | ||
}), | ||
new EndPoint({ | ||
type: 'group', | ||
hint: 'input', | ||
label: 'Stream', | ||
defaultChildData: { | ||
hint: 'input', | ||
type: 'target', | ||
ignoreDegree: true, | ||
}, | ||
allowAddAndRemoveChildren: true, | ||
children: [ | ||
new EndPoint({ | ||
hint: 'input', | ||
type: 'target', | ||
ignoreDegree: true, | ||
}), | ||
], | ||
}), | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
getHintPorts(node: Node<IMergeOperatorData>, hint: string) { | ||
return node.data.endPointOptions?.endPointList?.find( | ||
(item) => item.hint === hint, | ||
)?.children; | ||
} | ||
|
||
getIgnoreDegreeIds( | ||
node: Node<IMergeOperatorData<Record<string, any>>>, | ||
): string[] { | ||
const mainInputList = | ||
this.getHintPorts(node, 'input')?.map((item) => item.id) || []; | ||
return mainInputList; | ||
} | ||
|
||
generateBlockDeclarations( | ||
options: IGenerationOption<IMergeOperatorData<Record<string, any>>>, | ||
): string[] { | ||
const { node, formatVariableName } = options; | ||
|
||
const handleId = | ||
this.getHintPorts(node, 'output')?.find((item) => item.hint === 'output') | ||
?.id || ''; | ||
|
||
const mainInputList = | ||
this.getHintPorts(node, 'input')?.map((item) => item.id) || []; | ||
return [ | ||
...mainInputList.map( | ||
(inputId) => | ||
`const ${formatVariableName( | ||
inputId, | ||
)} = new ${EosCoreSymbol}.ModelState(undefined)`, | ||
), | ||
`const ${formatVariableName(handleId)} = ${EosOperatorsSymbol}.merge( | ||
[${mainInputList.map((id) => formatVariableName(id)).join(',')}], | ||
)`, | ||
]; | ||
} | ||
|
||
generateBlockOutput( | ||
options: IGenerationOption<IMergeOperatorData<Record<string, any>>>, | ||
): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockRelation( | ||
options: IGenerationOption<IMergeOperatorData<Record<string, any>>>, | ||
): string[] { | ||
const { node, formatVariableName, nodeGraph } = options; | ||
|
||
const mainInputList = | ||
this.getHintPorts(node, 'input')?.map((item) => item.id) || []; | ||
|
||
const sourceItems = nodeGraph.findSourceNodes(node.id) || []; | ||
const sourceItemMap = new Map( | ||
sourceItems.map((item) => [item.handleId, item]), | ||
); | ||
|
||
const relationList = mainInputList | ||
.map((inputId) => ({ | ||
inputId, | ||
targetId: sourceItemMap.get(inputId)?.relatedHandleId || '', | ||
})) | ||
.filter((item) => item.inputId && item.targetId); | ||
|
||
return [ | ||
...relationList.map( | ||
({ inputId, targetId }) => `${formatVariableName( | ||
targetId, | ||
)}.subscribe((val, extraInfo) => { | ||
${formatVariableName( | ||
inputId, | ||
)}.update(val, extraInfo.concat('${JSON.stringify({ | ||
currentNodeId: node.id, | ||
fromPortId: targetId, | ||
toPortId: inputId, | ||
})}')); | ||
});`, | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.