Yomguithereal / baobab-react

React integration for Baobab.
MIT License
309 stars 38 forks source link

Branch mixin does not update this.cursors and this.facets in componentWillReceiveProps #75

Closed davidtinker closed 8 years ago

davidtinker commented 9 years ago

This causes problems with components using cursor paths with properties in them when they attempt to change the data via this.cursors.

cursors: function(props) {
    return {data: ['views', 'users', props.user.id, 'balance']};
},

Elsewhere:

this.cursors.data.set(data);

Once properties have changed this.cursors will point at the wrong set of cursors.

The fix in mixins.js is simple:

componentWillReceiveProps: function componentWillReceiveProps(props) {
    if (!this.__facet) return;
    this.__facet.refresh([props, this.context]);

    this.cursors = this.__facet.cursors;
    this.facets = this.__facet.facets;

    this.setState(this.__facet.get());
}

I can send a PR if you like but its only 2 lines of code to add.

Yomguithereal commented 9 years ago

Hello @davidtinker. You are right indeed. I forgot this. Would it be possible for you to sketch a PR fixing the issue for mixins and higher-order components etc. also please?

Yomguithereal commented 9 years ago

This should be fixed with the latest version of the library. Do you need a retro-compatible fix?