fix: call consumer

This commit is contained in:
rorya.lyj 2020-08-16 10:27:06 +08:00
parent 7c4247392a
commit 70a1472182

View File

@ -237,6 +237,10 @@ export class DocumentInstance {
// this.ctxMap.set(id, ctx); // this.ctxMap.set(id, ctx);
} }
getComponentInstances(id: string): any[] | null {
return this.instancesMap.get(id) || null;
}
getNode(id: string): Node | null { getNode(id: string): Node | null {
return null; return null;
// return this.document.getNode(id); // return this.document.getNode(id);
@ -248,6 +252,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
private dispose?: () => void; private dispose?: () => void;
// TODO: history // TODO: history
readonly history: any; readonly history: any;
private emitter = new EventEmitter();
@obx.ref private _documentInstances: DocumentInstance[] = []; @obx.ref private _documentInstances: DocumentInstance[] = [];
get documentInstances() { get documentInstances() {
@ -269,6 +274,8 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
// sync device // sync device
this._device = host.device; this._device = host.device;
this.emitter.emit('rerender');
}); });
const documentInstanceMap = new Map<string, DocumentInstance>(); const documentInstanceMap = new Map<string, DocumentInstance>();
let initialEntry = '/'; let initialEntry = '/';
@ -287,48 +294,46 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
if (firstRun) { if (firstRun) {
initialEntry = path; initialEntry = path;
} else { } else {
if (this.history.location.pathname !== path) { // if (this.history.location.pathname !== path) {
this.history.replace(path); // this.history.replace(path);
} // }
} }
}); });
/* // const history = createMemoryHistory({
const history = createMemoryHistory({ // initialEntries: [initialEntry],
initialEntries: [initialEntry], // });
}); // this.history = history;
this.history = history; // history.listen((location, action) => {
history.listen((location, action) => { // host.project.open(location.pathname.substr(1));
host.project.open(location.pathname.substr(1)); // });
});
host.componentsConsumer.consume(async (componentsAsset) => { host.componentsConsumer.consume(async (componentsAsset) => {
if (componentsAsset) { if (componentsAsset) {
await this.load(componentsAsset); await this.load(componentsAsset);
this.buildComponents(); this.buildComponents();
} }
}); });
this._appContext = { // this._appContext = {
utils: { // utils: {
router: { // router: {
push(path: string, params?: object) { // push(path: string, params?: object) {
history.push(withQueryParams(path, params)); // history.push(withQueryParams(path, params));
}, // },
replace(path: string, params?: object) { // replace(path: string, params?: object) {
history.replace(withQueryParams(path, params)); // history.replace(withQueryParams(path, params));
}, // },
}, // },
legaoBuiltins: { // legaoBuiltins: {
getUrlParams() { // getUrlParams() {
const search = history.location.search; // const search = history.location.search;
return parseQuery(search); // return parseQuery(search);
} // }
} // }
}, // },
constants: {}, // constants: {},
}; // };
host.injectionConsumer.consume((data) => { host.injectionConsumer.consume((data) => {
// sync utils, i18n, contants,... config // sync utils, i18n, contants,... config
}); });
*/
} }
@computed get layout(): any { @computed get layout(): any {