| 91 | } |
| 92 | |
| 93 | export class Project implements IProject { |
| 94 | private emitter: IEventBus = createModuleEventBus('Project'); |
| 95 | |
| 96 | @obx.shallow readonly documents: IDocumentModel[] = []; |
| 97 | |
| 98 | private data: IPublicTypeProjectSchema = { |
| 99 | version: '1.0.0', |
| 100 | componentsMap: [], |
| 101 | componentsTree: [], |
| 102 | i18n: {}, |
| 103 | }; |
| 104 | |
| 105 | private _simulator?: ISimulatorHost; |
| 106 | |
| 107 | private isRendererReady: boolean = false; |
| 108 | |
| 109 | /** |
| 110 | * 模拟器 |
| 111 | */ |
| 112 | get simulator(): ISimulatorHost | null { |
| 113 | return this._simulator || null; |
| 114 | } |
| 115 | |
| 116 | @computed get currentDocument(): IDocumentModel | null | undefined { |
| 117 | return this.documents.find((doc) => doc.active); |
| 118 | } |
| 119 | |
| 120 | @obx private _config: any = {}; |
| 121 | @computed get config(): any { |
| 122 | // TODO: parse layout Component |
| 123 | return this._config; |
| 124 | } |
| 125 | set config(value: any) { |
| 126 | this._config = value; |
| 127 | } |
| 128 | |
| 129 | @obx.ref private _i18n: any = {}; |
| 130 | @computed get i18n(): any { |
| 131 | return this._i18n; |
| 132 | } |
| 133 | set i18n(value: any) { |
| 134 | this._i18n = value || {}; |
| 135 | } |
| 136 | |
| 137 | private documentsMap = new Map<string, DocumentModel>(); |
| 138 | |
| 139 | constructor(readonly designer: IDesigner, schema?: IPublicTypeProjectSchema, readonly viewName = 'global') { |
| 140 | makeObservable(this); |
| 141 | this.load(schema); |
| 142 | } |
| 143 | |
| 144 | private getComponentsMap(): IPublicTypeComponentsMap { |
| 145 | return this.documents.reduce<IPublicTypeComponentsMap>(( |
| 146 | componentsMap: IPublicTypeComponentsMap, |
| 147 | curDoc: IDocumentModel, |
| 148 | ): IPublicTypeComponentsMap => { |
| 149 | const curComponentsMap = curDoc.getComponentsMap(); |
| 150 | if (Array.isArray(curComponentsMap)) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…