diff --git a/_tests/smoke.spec.js b/_tests/smoke.spec.js index 29e6a4a..ca8d056 100644 --- a/_tests/smoke.spec.js +++ b/_tests/smoke.spec.js @@ -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; diff --git a/src/shouldInstrument.js b/src/shouldInstrument.js index 8bc690d..f44cb41 100644 --- a/src/shouldInstrument.js +++ b/src/shouldInstrument.js @@ -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' && @@ -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];