Skip to content

Commit

Permalink
fix(observers): Fix problems with observers triggering before mount
Browse files Browse the repository at this point in the history
  • Loading branch information
Thram committed Feb 20, 2017
1 parent ef28c46 commit 29850e1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ var connect = exports.connect = function connect(stateKey, ReactComponent) {
(0, _thrux.observe)(key, _this.observers[key]);
};

_this.componentDidMount = function () {
return (0, _isArray2.default)(stateKey) ? (0, _forEach2.default)(stateKey, _this.addObserver) : _this.addObserver(stateKey);
};

_this.componentWillUnmount = function () {
return (0, _forEach2.default)(_this.observers, function (observer, key) {
return (0, _thrux.removeObserver)(key, observer);
});
};

_this.state = (0, _assign2.default)(_this.state || {}, (0, _thrux.state)([].concat(stateKey)));
(0, _isArray2.default)(stateKey) ? (0, _forEach2.default)(stateKey, _this.addObserver) : _this.addObserver(stateKey);
return _this;
}

Expand Down
5 changes: 4 additions & 1 deletion dist/react-thrux.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-thrux.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-thrux.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-thrux.umd.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const connect = (stateKey, ReactComponent) => {
constructor(props) {
super(props);
this.state = assign(this.state || {}, state([].concat(stateKey)));
isArray(stateKey) ? forEach(stateKey, this.addObserver) : this.addObserver(stateKey);
}

addObserver = (key) => {
Expand All @@ -26,6 +25,8 @@ export const connect = (stateKey, ReactComponent) => {
observe(key, this.observers[key]);
};

componentDidMount = () => isArray(stateKey) ? forEach(stateKey, this.addObserver) : this.addObserver(stateKey);

componentWillUnmount = () => forEach(this.observers, (observer, key) => removeObserver(key, observer));
}
return ThruxComponent;
Expand Down

0 comments on commit 29850e1

Please sign in to comment.