mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: fork model
This commit is contained in:
parent
4d0ebc10a4
commit
aa4ea33698
@ -7,11 +7,11 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { action, define, observable } from '@formily/reactive';
|
||||
import type { IModelComponentProps } from '../types';
|
||||
import { FlowModel } from './flowModel';
|
||||
import { action, define, observable } from '@formily/reactive';
|
||||
import type { IModelComponentProps } from '../types';
|
||||
import { FlowModel } from './flowModel';
|
||||
|
||||
/**
|
||||
/**
|
||||
* ForkFlowModel 作为 FlowModel 的轻量代理实例:
|
||||
* - 共享 master(原始 FlowModel)上的所有业务数据与方法
|
||||
* - 仅在 props 层面拥有本地覆盖(localProps),其余字段全部透传到 master
|
||||
@ -20,7 +20,7 @@
|
||||
* - setter 方法中的 this 也指向 fork 实例,保持一致的上下文行为
|
||||
* - 不会被注册到 FlowEngine.modelInstances 中,保持 uid → master 唯一性假设
|
||||
*/
|
||||
export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
||||
export class ForkFlowModel<TMaster extends FlowModel = FlowModel> {
|
||||
/** 与 master 相同的 UID,用于日志调试 */
|
||||
public readonly uid: string;
|
||||
/** 调试标识,便于在日志或断言中快速识别 */
|
||||
@ -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 优先级最高
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象及其原型链上的属性描述符
|
||||
*/
|
||||
@ -191,7 +208,8 @@
|
||||
getProps(): IModelComponentProps {
|
||||
return { ...this.master.getProps(), ...this.localProps };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 类型断言:让 ForkFlowModel 可以被当作 FlowModel 使用
|
||||
export interface ForkFlowModel<TMaster extends FlowModel = FlowModel> extends FlowModel {}
|
||||
// 类型断言:让 ForkFlowModel 可以被当作 FlowModel 使用
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface ForkFlowModel<TMaster extends FlowModel = FlowModel> extends FlowModel {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user