Merge pull request #42 from status-im/fix/react-race-cond

fix: race condition on react HOC
This commit is contained in:
Iuri Matias 2019-10-02 22:03:28 -04:00 committed by GitHub
commit d77d25b7d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -21,16 +21,16 @@ export function observe(WrappedComponent) {
const subscription = this.props[prop].subscribe(
value => {
this.setState({
this.setState(state => ({
observedValues: {
...this.state.observedValues,
...state.observedValues,
[prop]: value
}
});
}));
},
err => {
// TODO: pass the error to the wrapped component
console.err(err);
console.error(err);
}
);
@ -41,11 +41,11 @@ export function observe(WrappedComponent) {
}
});
}
componentDidMount() {
Object.keys(this.props).forEach(this.subscribeToProp);
}
componentWillUnmount() {
this.state.subscriptions.forEach(subscription => {
subscription.unsubscribe();
@ -64,7 +64,7 @@ export function observe(WrappedComponent) {
// TODO: check if prevProps and currProps are different, and unsubscribe from prevProp
}
render() {
const props = Object.keys(this.props).reduce((accum, curr) => {
if(!isObservable(this.props[curr])){