make work as general react-redux memoizer
See original GitHub issueHey Anton, so basically for one we need it to work in the demo:
https://codesandbox.io/s/64mzx7vjmz?module=%2Fsrc%2Fconnect%2Findex.js
You mentioned that function references was the primary issue. So we need that.
Here’s a primary test that must work:
static getDerivedStateFromProps(nextProps, prevState) {
const { storeState, ...props } = nextProps
const state = selector(storeState, props)
console.log(prevState === state) // this must be true, when we are expecting it to be true :)
return prevState === state ? null : state
}
Then
dispatch({ type: 'BAR' })
. The comparison will always be will always befalse
, even when nothing in state has changed. So hopefully this is just a matter of making thedispatch
key/val work.
As far as this:
const fn = memoize(obj => ({ obj })
fn({ foo: 123 }) === fn({ foo: 123 })
Perhaps, we don’t in fact need that. So let’s just forget that for now.
Feel free to fork the demo, upgrade the deps, and paste a link to the working demo on the react-redux PR. I think it would be quite impressive to see all this come together in that demo. So for now, let’s just think about what’s actually being done in the demo, and then later I’m sure other cases will be brought to us.
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (10 by maintainers)
@faceyspacey - lets continue with spread in separate issue - https://github.com/theKashey/memoize-state/issues/5