Skip to content

Commit

Permalink
Merge branch 'master' of github.com:storeon/angular
Browse files Browse the repository at this point in the history
  • Loading branch information
irustm committed Nov 23, 2020
2 parents e281304 + ab64c00 commit 3376e33
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions projects/ng-storeon/src/lib/storeon.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export function UseStoreon<State, Events extends StoreonEvents<State> = any>(con
dispatcher?: string
}) {
return (cmpType) => {
const originalFactory = cmpType.ngComponentDef.factory;
cmpType.ngComponentDef.factory = () => {
const cmp = originalFactory(cmpType.ngComponentDef.type);

const isNg11 = !!cmpType.ɵfac;
const originalFactory = isNg11 ? cmpType.ɵfac : cmpType.ngComponentDef.factory;
const newFactory = () => {
const ngCompType = isNg11 ? cmpType.ɵcmp.type : cmpType.ngComponentDef.type;
const cmp = originalFactory(ngCompType);
const storeon = directiveInject<StoreonService<State, Events>>(StoreonService);

config.keys.forEach(key => cmp[key] = storeon.useStoreon(key));
Expand All @@ -28,5 +29,6 @@ export function UseStoreon<State, Events extends StoreonEvents<State> = any>(con
return cmp;
};

cmpType.ɵfac = newFactory;
};
}

0 comments on commit 3376e33

Please sign in to comment.