Closed minedeljkovic closed 8 years ago
you could also use https://github.com/acdlite/recompose/blob/master/docs/API.md#onlyupdateforkeys and just not include dispatcher.
Thanks, @namjul !
I didn't check their API in enough detail. Would onlyUpdateForKeys()
also ensure that call to dispatch
from wrapped component will be properly delegated to latest instance, despite wrapped component not being rendered with it? Also general behavior for redux-elm
views would be to update for all keys except dispatch
but that can probably be achieved by some function from recompose api.
But, final question still remains. Since redux-elm
is opinionated with usage of dispatch (it comes with forwardTo
) and immutability of model, shouldn't this be also included out of box?
Thanks @minedeljkovic and @namjul
I'd agree that this should definitely be part of the framework. IMO tagged dispatch should be memoized, so I'd just change implementation of forwardTo
.
Great! Looking forward to see that implementation.
I must confess I tried that approach, but all I came up with was pretty cumbersome to use in components like gif-viewers-pair
and gif-viewers-dynamic-list
. Hope it will not be that way. :)
@minedeljkovic i think it will just use the instance of dispatch it got initially.
Thanks, @namjul . That would not be good for this case.
so in your case your forwardTo function isn't static and it can change based on some logic.
Yes, I think that is generally the case in redux-elm
. Take for example gif-viewers-dynamic-list
. Components in dynamic list could be reordered so their dispatch path would change.
oh right .. missed that one :)
@minedeljkovic FYI actually "onlyUpdateForKeys" should also return the latest dispatch function. So whenever shouldUpdate returns true, the current dispatch function is used. https://github.com/acdlite/recompose/blob/master/src/packages/recompose/onlyUpdateForKeys.js
Solved in #14
In gif-viewers-pair example, it should be possible to make
random-gif-viewer
component pure, so it should rerender only when its model change. For example, when 'Request more' is clicked on 'funny cats' topic and new gif is received, component for 'funny dogs' topic should not be rerendered.This should be easily achievable with something like recompose pure helper.
But, the problem is that
forwardTo
calls propagate new instances ofdispatch
down the component hierarchy.I made proof of concept implementation of gif-viewers-pair example that tries to solve this problem. Here is higher order component views should use: higher order component that enables shallow render Here is example of usage.
Do you think solution to this problem (similar to the one I gave in this quick implementation, or something different) should be also part of
redux-elm
architecture?