Skip to content

Commit

Permalink
fix(effects): add support for Proxy objects in Effects (#2976)
Browse files Browse the repository at this point in the history
Closes #2975
  • Loading branch information
MortenGregersen authored Mar 23, 2021
1 parent 1cc1912 commit 5f5b679
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions modules/effects/spec/effect_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ describe('createEffect()', () => {
const fakeCreateEffect: any = () => {};
class Fixture {
a = fakeCreateEffect(() => of({ type: 'A' }));
b = new Proxy(
{},
{
get(_, prop) {
return () => Promise.resolve('bob');
},
}
);
}

const mock = new Fixture();
Expand Down
14 changes: 11 additions & 3 deletions modules/effects/src/effect_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,19 @@ export function getCreateEffectMetadata<
const propertyNames = Object.getOwnPropertyNames(instance) as Array<keyof T>;

const metadata: EffectMetadata<T>[] = propertyNames
.filter(
(propertyName) =>
.filter((propertyName) => {
if (
instance[propertyName] &&
instance[propertyName].hasOwnProperty(CREATE_EFFECT_METADATA_KEY)
)
) {
// If the property type has overridden `hasOwnProperty` we need to ensure
// that the metadata is valid (containing a `dispatch`property)
// https://github.com/ngrx/platform/issues/2975
const property = instance[propertyName] as any;
return property[CREATE_EFFECT_METADATA_KEY].hasOwnProperty('dispatch');
}
return false;
})
.map((propertyName) => {
const metaData = (instance[propertyName] as any)[
CREATE_EFFECT_METADATA_KEY
Expand Down

0 comments on commit 5f5b679

Please sign in to comment.