Add default model view input types and validation (#1397)

This commit is contained in:
Matt Irvine
2018-05-14 16:20:19 -07:00
committed by GitHub
parent 89c48bbe75
commit 9bd45cf66a
14 changed files with 363 additions and 118 deletions

View File

@@ -39,9 +39,10 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
private _onEventEmitter = new Emitter<any>();
initializeModel(rootComponent: IComponentShape): void {
initializeModel(rootComponent: IComponentShape, validationCallback: (componentId: string) => Thenable<boolean>): void {
let descriptor = this.defineComponent(rootComponent);
this.rootDescriptor = descriptor;
this.modelStore.registerValidationCallback(validationCallback);
// Kick off the build by detecting changes to the model
this.changeRef.detectChanges();
}
@@ -91,10 +92,6 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
this.queueAction(componentId, (component) => component.setProperties(properties));
}
setValid(componentId: string, valid: boolean): void {
this.queueAction(componentId, (component) => component.setValid(valid));
}
private queueAction<T>(componentId: string, action: (component: IComponent) => T): void {
this.modelStore.eventuallyRunOnComponent(componentId, action).catch(err => {
// TODO add error handling
@@ -113,4 +110,8 @@ export abstract class ViewBase extends AngularDisposable implements IModelView {
public get onEvent(): Event<IComponentEventArgs> {
return this._onEventEmitter.event;
}
public validate(componentId: string): Thenable<boolean> {
return new Promise(resolve => this.modelStore.eventuallyRunOnComponent(componentId, component => resolve(component.validate())));
}
}