-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shouldUpdate hook? (v2.0.0-rc6) #336
Comments
Just haven't gotten around to doing it yet. I wanted to give components a default The best thing is probably to just make import shouldUpdate from 'immutable-should-update'
export default {
render,
shouldUpdate
} |
Should update should probably just look like:
|
yeah, i agree, |
Only reason I was hesitant to add it was that you can get the same thing with memoization, which is more 'standard' than something like this. |
actually, that seems like a pretty good way to accomplish it, given that there aren't any React-like "classes" in the way... |
100% agree |
I just realized memoization isn't straight-forward. I can make a The way around this is to make a
|
I think the problem with memoizing is universal apps. |
The way you implemented it, you memoize the last rendered output of a component as opposed to memoizing the last rendered output per component instance. Below was my attempt at it: import equals from 'is-equal-shallow';
const lastRenderedByPath = {};
const defaultShouldUpdate = (model, prevModel) => !equals(model, prevModel);
const createMemoizedRender =
(render, shouldUpdate = defaultShouldUpdate) =>
model => {
const { path } = model;
if (!lastRenderedByPath[path] || shouldUpdate(model, lastRenderedByPath[path])) {
const rendered = render(model);
// Not universal friendly
lastRenderedByPath[path] = rendered;
}
return lastRenderedByPath[path];
}; |
ah, lame, i knew i was missing something |
got it, fixed it [email protected]. |
also, i wouldn't use is-equal-shallow as a default there. is-equal-shallow will always return false if any values are objects: isEqualShallow({ props: {} }, { props: {} }) // => false |
Yeah in fact I meant to shallow compare props, not models ^^ const defaultShouldUpdate = (model, prevModel) => !equals(model.props, prevModel.props); |
cool! i guess this also sets the precedent that other React-ism's can be implemented as Component decorators.
|
IMO the default EDIT: This also has the issue that any updates at all to function shouldUpdate (prev, next) {
// compare .props, .children, .context in both. If props is shallow equal
// and context and children are exactly the same, just bail.
} Will never return false on any re-render, because |
It seems the v2 API removed the shouldUpdate hook. Is there any reason for this?
The text was updated successfully, but these errors were encountered: