Skip to content

Commit

Permalink
handle objects with empty prototype, fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Nov 2, 2019
1 parent 993d802 commit d810b92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions _tests/smoke.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ describe('proxy', () => {
expect(proxyEqual(o1, o2, trapped.affected)).to.be.equal(false);
});

it('handles orphan objects', () => {
const obj = Object.create(null);
obj.field=42;
const trapped = proxyState(obj);
expect(trapped.state.field).to.be.equal(42);
expect(trapped.affected).to.be.deep.equal(['.field']);
});

it('detect self', () => {
const A = {a: 1};
const B = proxyState(A).state;
Expand Down
5 changes: 4 additions & 1 deletion src/shouldInstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const handlers = {
const globalObj = typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {};

export function shouldInstrument({constructor}) {
if(!constructor) {
return true;
}
const name = constructor.name;
const isBuiltIn = (
typeof constructor === 'function' &&
Expand All @@ -45,4 +48,4 @@ export function shouldInstrument({constructor}) {
return !isBuiltIn || handlers.hasOwnProperty(name);
}

export const getCollectionHandlers = ({constructor}) => handlers[constructor.name];
export const getCollectionHandlers = ({constructor}) => constructor && handlers[constructor.name];

0 comments on commit d810b92

Please sign in to comment.