ModelFactory: add hasComponent method

This commit is contained in:
Alice Gaudon 2020-11-11 18:35:49 +01:00
parent ead3c8ce1e
commit bb8b44b5a3

View File

@ -32,6 +32,10 @@ export default class ModelFactory<M extends Model> {
this.components.push(modelComponentFactory); this.components.push(modelComponentFactory);
} }
public hasComponent(modelComponentFactory: ModelComponentFactory<M>): boolean {
return !!this.components.find(c => c === modelComponentFactory);
}
public create(data: Pick<M, keyof M>, isNewModel: boolean): M { public create(data: Pick<M, keyof M>, isNewModel: boolean): M {
const model = new this.modelType(this as unknown as ModelFactory<never>, isNewModel); const model = new this.modelType(this as unknown as ModelFactory<never>, isNewModel);
for (const component of this.components) { for (const component of this.components) {