arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

React-pure-render integration #61

Closed Tjorriemorrie closed 8 years ago

Tjorriemorrie commented 8 years ago

Does this library work with react-pure-render?

I've tried:

import shouldPureComponentUpdate from 'react-pure-render/function';
export default class App extends React.Component {
    shouldComponentUpdate = shouldPureComponentUpdate;

instead of:

freezer.on('update', () => this.forceUpdate());

But it didn't trigger an update.

leesei commented 8 years ago

I think the forceUpdate() call should be in the top most App component.

react-pure-render should be used for other pure components (whose render() function only depends on this.state and this.props), for example TodoList and Footer in freezer-todomvc. See my Footer code which uses PureRenderMixin.

(TodoItem is also pure but it is already bound by TodoList, so we don't have to implement its shouldComponentUpdate())

Tjorriemorrie commented 8 years ago

OK, so I assume it's useless then because of how freezer works. Thanks for the advice.

arqex commented 8 years ago

@Tjorriemorrie there is no problem using freezer and react-pure-render together. Your freezer store should be read by your top component (as @leesei recommends ) and its data is passed down through its children props. Only this top component should use the forceUpdate snippet to make your app reactive.

All the children should receive the data from their props and they can be pure components, getting the benefit of using react-pure-render.

leesei commented 8 years ago

I've updated my comment.

@arqex do you think my commit is useful for freezer-todomvc? I can create PR after changing dependency to react-pure-render.