fix: fork model

This commit is contained in:
chenos 2025-06-19 13:54:45 +08:00
parent 4d0ebc10a4
commit aa4ea33698

View File

@ -38,6 +38,9 @@
/** fork 在 master.forks 中的索引 */
public readonly forkId: number;
/** 用于共享上下文的对象,存储跨 fork 的共享数据 */
private _sharedContext: Record<string, any> = {};
constructor(master: TMaster, initialProps: IModelComponentProps = {}, forkId = 0) {
this.master = master;
this.uid = master.uid;
@ -117,6 +120,20 @@
});
}
public setSharedContext(ctx: Record<string, any>) {
this._sharedContext = ctx;
}
public getSharedContext() {
if (this.async || !this.parent) {
return this._sharedContext;
}
return {
...this.parent?.getSharedContext(),
...this._sharedContext, // 当前实例的 context 优先级最高
};
}
/**
*
*/
@ -194,4 +211,5 @@
}
// 类型断言:让 ForkFlowModel 可以被当作 FlowModel 使用
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ForkFlowModel<TMaster extends FlowModel = FlowModel> extends FlowModel {}