I’ve started studying how an immutable version of Connect could work. I tried an implementation based on immer and I’m trying another one now using valtio.
The goals are:
Take advantage of the Redux DevTools (as opposed to creating our own DevTools).
Prepare it for Concurrent mode (immutable state managers are a better fit for Concurrent).
Add action/state hooks (this will supersede the Frontity Hooks).
Extra goals can be:
Finally figure out how to create nested derived state.
Open questions:
Switch to a setter function: setState(s => s.x = "x") vs state.x = "x". This would add compatibility with old browsers and would easy the implementation.
This might or might not require a backward compatible change, depending on the final API (so Frontity v2), but it is a possibility.
I’ve recorded a video with a summary of the current status:
Next steps: I want to do a couple of optimizations, finish the types of Derived and start working on the proxification of the store when passed to actions/components.
I am confident that I will be able to show who triggered the action/mutation in the Redux DevTools. I think we could use the action object to log it:
I see that the repo has the same issue, but I wasn’t even able to run it because of an issue in react-scripts :
TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'
I would normally try to fix the bug, but I think that the offending snippet is not possible (you cannot pass store to the wrapActions() ) so I’m not sure what the intention here was:
// Init the store to pass its reference to the wrappers.
const store: ResolveStore<Store> = {
state: wrapState(mutableState),
actions: wrapActions(store, initialStore.actions)
};