3 ms·
This mirrors exactly the way I've been approaching redux recently as well following the same realization. I feel like this is much cleaner and easier to reason
by jmcqk6 8y ago
This mirrors exactly the way I've been approaching redux recently as well following the same realization. I feel like this is much cleaner and easier to reason about.
- acemarke 8y agoHi, I'm a Redux maintainer. Got any examples of this? Also, how do you feel it's better than a typical Redux app setup?
- mattdeboard 8y agoIt seems like the main difference with a reducer is that the reducer just returns `state`, not `(state, action)`. I'm reading this for the first time but that's how I'm reading it. But y'all must be storing this `(point-in-time-state, action-that-produced-state)` somewhere, because the Redux Chrome plugin displays this data. Was I wrong in thinking the Chrome plugin was just visualizing data already stored by Redux?
- acemarke 8y agoNo, the core Redux store does _not_ store any action history by itself. It's simply: function createStore(reducer) { var state var listeners = [] function getState() { return state } function dispatch(action) { state = reducer(state, action) listeners.forEach(listener => listener()) } } It's the Redux DevTools that do the real work of actually saving an action log, like what was described above. In fact, canceling actions does actually work by re-running the actions in the same sequence, minus the ones that are being skipped, to generate the new state. That logic has been split out into its own package, which you can see in the https://github.com/zalmoxisus/redux-devtools-instrument https://github.com/zalmoxisus/redux-devtools-instrument repo. Very vaguely related side note: earlier this year, I spent a couple days to add an "action stack trace" tab to the Redux DevTools Extension. When you click on an action, in addition to seeing the action contents, state tree, and diff, you can now also see an actual formatted stack trace that shows you exactly where the action was dispatched from (including the actual code if you've got sourcemaps enabled). Sadly, the extension maintainer has been MIA recently, so we're considering forking it into the Redux org. Until then, you can download my custom build of the extension here: https://github.com/zalmoxisus/redux-devtools-extension/issues/429#issuecomment-417955282 https://github.com/zalmoxisus/redux-devtools-extension/issue...
- mattdeboard 8y agoThat's really interesting. I honestly haven't given Redux DevTools much thought despite the fact I use it daily as a core part of my workflow. I thought, like I said before, it was mostly just visualizing artifacts produced normally by Redux. Makes the browser extension much more interesting! edit: Here's the link where it's implemented in redux-devtools if anyone else is curious https://github.com/reduxjs/redux-devtools/blob/master/src/createDevTools.js#L21-L24 https://github.com/reduxjs/redux-devtools/blob/master/src/cr...
- tobr 8y agoFor me it’s been experimental so far. I’ve not actually used Redux in these experiments, but I’m inspired by where Redux and Re-reselect has been leading me for the past two years or so. The pattern is a gold mine of interesting implications that I’m still discovering, such as real time collaboration, and speculative precomputation/prefetching. As it moves all the focus from reducers to selectors, and has quite different requirements for how to do caching there, it’s led me to work on a custom selector library with quite different API from reselect/re-reselect. I’d like to release it when my experiments start to feel... less experimental.