Skip to content

Commit

Permalink
fix(core): do not fire onInit event twice
Browse files Browse the repository at this point in the history
Closes #900
  • Loading branch information
B4nan committed Oct 5, 2020
1 parent 5612759 commit 9485f48
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions packages/core/src/entity/EntityFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class EntityFactory {
this.unitOfWork.registerManaged(entity, data, options.refresh && options.initialized, options.newEntity);
}

this.runHooks(entity, meta);
this.eventManager.dispatchEvent(EventType.onInit, { entity, em: this.em });

return entity as New<T, P>;
}
Expand Down Expand Up @@ -189,15 +189,4 @@ export class EntityFactory {
});
}

private runHooks<T>(entity: T, meta: EntityMetadata<T>): void {
/* istanbul ignore next */
const hooks = meta.hooks?.onInit || [];

if (hooks.length > 0) {
hooks.forEach(hook => (entity[hook] as unknown as () => void)());
}

this.eventManager.dispatchEvent(EventType.onInit, { entity, em: this.em });
}

}

0 comments on commit 9485f48

Please sign in to comment.