fix: race condition on react HOC
This commit is contained in:
parent
7666d6f6a2
commit
b2c49bdada
|
@ -21,16 +21,16 @@ export function observe(WrappedComponent) {
|
||||||
|
|
||||||
const subscription = this.props[prop].subscribe(
|
const subscription = this.props[prop].subscribe(
|
||||||
value => {
|
value => {
|
||||||
this.setState({
|
this.setState(state => ({
|
||||||
observedValues: {
|
observedValues: {
|
||||||
...this.state.observedValues,
|
...state.observedValues,
|
||||||
[prop]: value
|
[prop]: value
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
// TODO: pass the error to the wrapped component
|
// TODO: pass the error to the wrapped component
|
||||||
console.err(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ export function observe(WrappedComponent) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
Object.keys(this.props).forEach(this.subscribeToProp);
|
Object.keys(this.props).forEach(this.subscribeToProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.state.subscriptions.forEach(subscription => {
|
this.state.subscriptions.forEach(subscription => {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
|
@ -64,7 +64,7 @@ export function observe(WrappedComponent) {
|
||||||
|
|
||||||
// TODO: check if prevProps and currProps are different, and unsubscribe from prevProp
|
// TODO: check if prevProps and currProps are different, and unsubscribe from prevProp
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const props = Object.keys(this.props).reduce((accum, curr) => {
|
const props = Object.keys(this.props).reduce((accum, curr) => {
|
||||||
if(!isObservable(this.props[curr])){
|
if(!isObservable(this.props[curr])){
|
||||||
|
|
Loading…
Reference in New Issue