-
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
17 changed files
with
314 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { type Atom } from '../../ModelState/State'; | ||
import { ModelState } from '../..'; | ||
|
||
export function combine< | ||
ObservableSubjectList extends Array<Atom<any>>, | ||
AppendObservableSubjectList extends Array<Atom<any>>, | ||
>( | ||
streamSource: ObservableSubjectList, | ||
appendSource: AppendObservableSubjectList, | ||
) { | ||
const result = new ModelState<any[]>([]); | ||
|
||
streamSource.forEach((input, index) => { | ||
input.subscribe((_value, extraInfo) => { | ||
const allValue = [...streamSource, ...appendSource].map( | ||
(item) => item.current, | ||
); | ||
result.update(allValue, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { constValue } from './constValue'; | ||
export { proxyData } from './proxyData'; | ||
export { sum } from './sum'; | ||
export { combine } from './combine'; | ||
export { transform } from './transform'; |
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,17 @@ | ||
import { type Atom } from '../../ModelState/State'; | ||
import { ModelState } from '../..'; | ||
|
||
export function transform<StreamValue, ResultValue>( | ||
steam: Atom<StreamValue>, | ||
action: (value: StreamValue) => ResultValue, | ||
) { | ||
return steam.pipe((observer) => { | ||
const result = new ModelState<ResultValue | undefined>(undefined); | ||
|
||
observer.subscribe((value, extra) => { | ||
result.update(action(value), extra.concat('transform')); | ||
}); | ||
|
||
return result; | ||
}); | ||
} |
128 changes: 128 additions & 0 deletions
128
packages/flow/src/Diagrams/Operators/CombineOperator/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,128 @@ | ||
import { type Node } from 'reactflow'; | ||
import { type IGenerationOption } from '../../Compiler/graph'; | ||
import { NodeTypeEnum } from '../../Nodes/NodeTypeEnum'; | ||
import { MetaOperator } from '../Operator'; | ||
import { EndPoint, type ICombineOperatorData } from '../types'; | ||
import { EosOperatorsSymbol } from '../../Compiler/runtime'; | ||
|
||
export class CombineOperator | ||
extends MetaOperator<ICombineOperatorData> | ||
implements MetaOperator<ICombineOperatorData> | ||
{ | ||
constructor() { | ||
super({ | ||
operatorName: 'Combine', | ||
operatorType: 'CombineOperator', | ||
nodeType: NodeTypeEnum.Node, | ||
}); | ||
} | ||
|
||
nodeColor?: string | undefined = '#C21292'; | ||
|
||
create(): Node<ICombineOperatorData<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: 'mainInput', | ||
label: 'Main Stream', | ||
defaultChildData: { | ||
hint: 'mainSource', | ||
type: 'target', | ||
}, | ||
allowAddAndRemoveChildren: true, | ||
children: [ | ||
new EndPoint({ | ||
hint: 'mainSource', | ||
type: 'target', | ||
}), | ||
], | ||
}), | ||
new EndPoint({ | ||
type: 'group', | ||
hint: 'appendInput', | ||
label: 'Append Stream', | ||
defaultChildData: { | ||
hint: 'appendSource', | ||
type: 'target', | ||
}, | ||
allowAddAndRemoveChildren: true, | ||
children: [ | ||
new EndPoint({ | ||
hint: 'appendSource', | ||
type: 'target', | ||
}), | ||
], | ||
}), | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
getHintPorts(node: Node<ICombineOperatorData>, hint: string) { | ||
return node.data.endPointOptions?.endPointList?.find( | ||
(item) => item.hint === hint, | ||
)?.children; | ||
} | ||
|
||
getMainInputPorts(node: Node<ICombineOperatorData>) { | ||
return this.getHintPorts(node, 'mainInput'); | ||
} | ||
|
||
getAppendInputPorts(node: Node<ICombineOperatorData>) { | ||
return this.getHintPorts(node, 'appendInput'); | ||
} | ||
|
||
generateBlockDeclarations( | ||
options: IGenerationOption<ICombineOperatorData>, | ||
): string[] { | ||
const { node, formatVariableName, nodeGraph } = options; | ||
const handleId = | ||
this.getHintPorts(node, 'output')?.find((item) => item.hint === 'output') | ||
?.id || ''; | ||
|
||
const mainInputSet = new Set( | ||
this.getMainInputPorts(node)?.map((item) => item.id), | ||
); | ||
const appendInputSet = new Set( | ||
this.getAppendInputPorts(node)?.map((item) => item.id), | ||
); | ||
|
||
const sourceItems = nodeGraph.findSourceNodes(node.id) || []; | ||
const mainInputSourceIds = sourceItems | ||
.filter((item) => mainInputSet.has(item.handleId)) | ||
.map((item) => item.relatedHandleId); | ||
|
||
const appendInputSourceIds = sourceItems | ||
.filter((item) => appendInputSet.has(item.handleId)) | ||
.map((item) => item.relatedHandleId); | ||
|
||
return [ | ||
`const ${formatVariableName(handleId)} = ${EosOperatorsSymbol}.combine( | ||
[${mainInputSourceIds.map((id) => formatVariableName(id)).join(',')}], | ||
[${appendInputSourceIds.map((id) => formatVariableName(id)).join(',')}] | ||
)`, | ||
]; | ||
} | ||
|
||
generateBlockOutput(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockRelation(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
packages/flow/src/Diagrams/Operators/EffectOperator/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,46 @@ | ||
import { type Node } from 'reactflow'; | ||
import { type IGenerationOption } from '../../Compiler/graph'; | ||
import { NodeTypeEnum } from '../../Nodes/NodeTypeEnum'; | ||
import { MetaOperator } from '../Operator'; | ||
import { EndPoint, type IEffectOperatorData } from '../types'; | ||
|
||
export class EffectOperator | ||
extends MetaOperator<IEffectOperatorData> | ||
implements MetaOperator<IEffectOperatorData> | ||
{ | ||
constructor() { | ||
super({ | ||
operatorName: 'Effect', | ||
operatorType: 'EffectOperator', | ||
nodeType: NodeTypeEnum.Node, | ||
}); | ||
} | ||
|
||
create(): Node<IEffectOperatorData<Record<string, any>>> { | ||
return super.create({ | ||
endPointOptions: { | ||
endPointList: [ | ||
new EndPoint({ | ||
type: 'target', | ||
hint: 'input', | ||
label: 'input', | ||
}), | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
nodeColor?: string | undefined = '#F3F8FF'; | ||
|
||
generateBlockDeclarations(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockOutput(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockRelation(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
packages/flow/src/Diagrams/Operators/TransformOperator/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,51 @@ | ||
import { type Node } from 'reactflow'; | ||
import { type IGenerationOption } from '../../Compiler/graph'; | ||
import { NodeTypeEnum } from '../../Nodes/NodeTypeEnum'; | ||
import { MetaOperator } from '../Operator'; | ||
import { EndPoint, type ITranformOperatorData } from '../types'; | ||
|
||
export class TransformOperator | ||
extends MetaOperator<ITranformOperatorData> | ||
implements MetaOperator<ITranformOperatorData> | ||
{ | ||
constructor() { | ||
super({ | ||
operatorName: 'Transform', | ||
operatorType: 'TransformOperator', | ||
nodeType: NodeTypeEnum.Node, | ||
}); | ||
} | ||
|
||
create(): Node<ITranformOperatorData<Record<string, any>>> { | ||
return super.create({ | ||
endPointOptions: { | ||
endPointList: [ | ||
new EndPoint({ | ||
type: 'source', | ||
hint: 'output', | ||
label: 'output', | ||
}), | ||
new EndPoint({ | ||
type: 'target', | ||
hint: 'input', | ||
label: 'input', | ||
}), | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
nodeColor?: string | undefined = '#F3F8FF'; | ||
|
||
generateBlockDeclarations(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockOutput(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
|
||
generateBlockRelation(options: IGenerationOption<any>): string[] { | ||
return []; | ||
} | ||
} |
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.