Skip to content

Commit 38a108c

Browse files
author
Daniel de la Cruz
committed
Merge pull request #3 from danderu/hotfix/undefined_context
fix undefined context when app is not wrapped in a ToggleApp
2 parents 02e7ded + d6dee51 commit 38a108c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-feature-toggle",
33
"description": "A simple solution for implementing feature toggles in react",
4-
"version": "0.6.0",
4+
"version": "0.6.1",
55
"main": "lib/",
66
"scripts": {
77
"clean:lib": "rimraf ./lib/*",

src/toggle-component/index.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React, { Component, PropTypes } from 'react';
22

33
const ToggleComponent = (def, ...toggled) => class ToggleComponent extends Component {
4+
constructor(...args) {
5+
super(...args);
6+
this._toggles = this.context.toggles || {};
7+
}
48
static get childContextTypes() {
59
return Object.assign({}, super.childContextTypes, {
6-
toggles: React.PropTypes.object
10+
toggles: PropTypes.object
711
});
812
}
913
getChildContext() {
10-
return (super.getChildContext && super.getChildContext()) || {};
14+
return (super.getChildContext && super.getChildContext()) || { toggles: {} };
1115
}
1216
static get contextTypes() {
1317
return {
@@ -16,10 +20,10 @@ const ToggleComponent = (def, ...toggled) => class ToggleComponent extends Compo
1620
}
1721
render() {
1822
const Toggle = toggled.reduce( (actual, t) => {
19-
return Object.keys(this.context.toggles).find(k => k === t.displayName) ? t : actual;
23+
return Object.keys(this._toggles).find(k => k === t.displayName) ? t : actual;
2024
}, def);
2125

22-
const props = Object.assign({}, this.props, this.context.toggles[Toggle.displayName] && this.context.toggles[Toggle.displayName].props);
26+
const props = Object.assign({}, this.props, this._toggles[Toggle.displayName] && this._toggles[Toggle.displayName].props);
2327
return <Toggle {...props} />;
2428
}
2529
};

0 commit comments

Comments
 (0)