Skip to content

Commit

Permalink
feat(react): warn on non-whitelisted config property
Browse files Browse the repository at this point in the history
...when it's retrieved in the browser runtime.
  • Loading branch information
Emanuel Kluge authored and jhiode committed Dec 17, 2019
1 parent 4673dcf commit e914be4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/react/config/mixin.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,33 @@ const { Mixin } = require('hops-mixin');

const { Provider } = require('./context');

const warnOnIncompleteBrowserWhitelist = config => {
if (process.env.NODE_ENV === 'development' && typeof Proxy === 'function') {
return new Proxy(config, {
get: (obj, prop) => {
const value = obj[prop];

if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
console.warn(
`The property "${prop}" does not exist. Did you forget to add it to the browserWhitelist of your Hops config?`
);
}

return value;
},
});
}

return config;
};

class HopsReactConfigMixin extends Mixin {
enhanceElement(reactElement) {
return React.createElement(Provider, { value: this.config }, reactElement);
return React.createElement(
Provider,
{ value: warnOnIncompleteBrowserWhitelist(this.config) },
reactElement
);
}
}

Expand Down

0 comments on commit e914be4

Please sign in to comment.