React.js pure render performance anti-pattern
medium.com
medium.com
1: Example of arrow functions + Class property initializer: http://babeljs.io/blog/2015/06/07/react-on-es6-plus/ 2: Default Props: https://facebook.github.io/react/docs/reusable-components.ht...
There's probably a lesson to be learned in here, but if I wrote an article every time I wrote bad code, I wouldn't have time to write any bad code ;)
Edit: This particular issue is pretty common, and it's good to draw attention to it, but let's just call it what it is - a common bug.
The issue here mostly being that PureRenderMixin uses identity because Javascript has little to no support for equality.
Depending on how often that happens (and thus subsequent extra reconciliations or even re-renders) versus the cost of checking collections for equality (generally O(n), versus O(1) for identity), you may get extra performances from checking for equality.
> new Date(0) === new Date(0)
<- false > Immutable.List.of(1) === Immutable.List.of(1)
< false = $3
which is why Immutable.is exists.What's wrong with that? What are the alternatives?
If you follow a 'get started with redux' thing and end up with a root reducer that uses combineReducers: You're talking about the outermost 'state' object? Because any reducer that you write can certainly accept/understand/return immutables, right?
If I picked that up correctly: Is that a problem for a single combineReducers at the root? Because if all the properties of that thing are immutable, wouldn't you get the cheap identity based comparison benefits whenever you pass on props.foo in your store-aware component?
We don't use it though, it's really easy to just create your own version and use that and preferred to have one less dependency.
const List = props =>
<ul>
props.items.map(item =>
<li onClick={e => props.itemClicked(item.id)}>{item.name}</li>
)
</ul>Edit: To elaborate, you can solve this by using pagination (a common solution), or, if you want the user to be able to scroll and not click, occlusion culling. Someone out there must have written an occlusion culling library for React by now, surely.