Run initial modelview actions first (#13317)

* Run initial modelview actions first

* add param

* Comments and typings

* Catch promise error

* fix db projects test

* remove extra calls
This commit is contained in:
Charles Gagnon
2020-11-10 17:00:16 -08:00
committed by GitHub
parent b4dd0442c5
commit b83da2dfa8
6 changed files with 70 additions and 42 deletions

View File

@@ -60,12 +60,12 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
throw new Error(nls.localize('componentTypeNotRegistered', "Could not find component for type {0}", ModelComponentTypes[component.type]));
}
let descriptor = this.modelStore.createComponentDescriptor(typeId, component.id);
this.setProperties(component.id, component.properties);
this.setLayout(component.id, component.layout);
this.registerEvent(component.id);
this.setProperties(component.id, component.properties, true);
this.setLayout(component.id, component.layout, true);
this.registerEvent(component.id, true);
if (component.itemConfigs) {
for (let item of component.itemConfigs) {
this.addToContainer(component.id, item);
this.addToContainer(component.id, item, undefined, true);
}
}
@@ -84,12 +84,12 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
this.queueAction(componentId, (component) => component.clearContainer());
}
addToContainer(containerId: string, itemConfig: IItemConfig, index?: number): void {
addToContainer(containerId: string, itemConfig: IItemConfig, index?: number, initial: boolean = false): void {
// Do not return the promise as this should be non-blocking
this.queueAction(containerId, (component) => {
let childDescriptor = this.defineComponent(itemConfig.componentShape);
component.addToContainer(childDescriptor, itemConfig.config, index);
});
}, initial);
}
removeFromContainer(containerId: string, itemConfig: IItemConfig): void {
@@ -100,11 +100,11 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
});
}
setLayout(componentId: string, layout: any): void {
setLayout(componentId: string, layout: any, initial: boolean = false): void {
if (!layout) {
return;
}
this.queueAction(componentId, (component) => component.setLayout(layout));
this.queueAction(componentId, (component) => component.setLayout(layout), initial);
}
setItemLayout(containerId: string, itemConfig: IItemConfig): void {
@@ -114,24 +114,22 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
});
}
setProperties(componentId: string, properties: { [key: string]: any; }): void {
setProperties(componentId: string, properties: { [key: string]: any; }, initial: boolean = false): void {
if (!properties) {
return;
}
this.queueAction(componentId, (component) => component.setProperties(properties));
this.queueAction(componentId, (component) => component.setProperties(properties), initial);
}
refreshDataProvider(componentId: string, item: any): void {
this.queueAction(componentId, (component) => component.refreshDataProvider(item));
}
private queueAction<T>(componentId: string, action: (component: IComponent) => T): void {
this.modelStore.eventuallyRunOnComponent(componentId, action).catch(err => {
// TODO add error handling
});
private queueAction<T>(componentId: string, action: (component: IComponent) => T, initial: boolean = false): void {
this.modelStore.eventuallyRunOnComponent(componentId, action, initial);
}
registerEvent(componentId: string) {
registerEvent(componentId: string, initial: boolean = false) {
this.queueAction(componentId, (component) => {
this._register(component.registerEventHandler(e => {
let modelViewEvent: IModelViewEventArgs = assign({
@@ -140,7 +138,7 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
}, e);
this._onEventEmitter.fire(modelViewEvent);
}));
});
}, initial);
}
public get onEvent(): Event<IModelViewEventArgs> {
@@ -148,18 +146,18 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
}
public validate(componentId: string): Thenable<boolean> {
return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate())));
return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate()), false));
}
public setDataProvider(handle: number, componentId: string, context: any): any {
return this.queueAction(componentId, (component) => component.setDataProvider(handle, componentId, context));
return this.queueAction(componentId, (component) => component.setDataProvider(handle, componentId, context), false);
}
public focus(componentId: string): void {
return this.queueAction(componentId, (component) => component.focus());
return this.queueAction(componentId, (component) => component.focus(), false);
}
public doAction(componentId: string, action: string, ...args: any[]): void {
return this.queueAction(componentId, (component) => component.doAction(action, ...args));
return this.queueAction(componentId, (component) => component.doAction(action, ...args), false);
}
}