From b1cf0d8fbdb967ab5d86a2c445c7728acaf5e30f Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Sat, 30 Jun 2018 16:12:03 +0530 Subject: [PATCH] Add Object.seal checks and warning This will help during development that you are warned that something will break in an old browser without the need to check in the old browser. --- src/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.js b/src/index.js index dbb9054..325c2a1 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,9 @@ export const ReactChopper = (target, componentReference) => { if (typeof value === "object") { value = proxify(value, [...path, key]); } + if (!Object.prototype.hasOwnProperty.call(target, key)) { + console.warn("You are trying to set a new property \"" + key + "\" to your proxified object which was not present in the beginning. This will not work in polyfilled browsers as properties need to be sealed."); + } target[key] = value; componentReference.setState({ [key]: value }); return true; @@ -21,6 +24,10 @@ export const ReactChopper = (target, componentReference) => { } } let p = new Proxy(obj, makeHandler(path)); + if (typeof Object.seal === "function") { + Object.seal(obj); + Object.seal(p); + } preproxy.set(p, obj); return p; };