Skip to content

Instantly share code, notes, and snippets.

@rmadsen
rmadsen / PubsubRedux.md
Last active April 5, 2017 13:53
Proposal for a redux-like pub-sub store

Note: I realize the below is fairly abstract, and would be happy to come up with some pseudo code if that would make things clearer. I'm still in the process of trying to piece together my thoughts. Thanks in advance for reading and for the feedback!

I have two motivations for creating a pub-sub variant of Redux, which I'll get to in a minute. I first want to describe what I mean by a "pub-sub redux variant." I'm enamored with redux's action/reducer model, but feel like there is an unnecessary limitation where components can only be connected to the root of the store state. What I'd like to propose is that instead of react-redux's mapStateToProps function, connect expects a collection of subscriptions. Each subscription is an object of the form { pathToSubscribeTo, stateToPropsHandlerFn }, where pathToSubscribeTo is a pointer/string representing a node in the state tree, and stateToPropsHandlerFn is a function that takes the updated node and returns some props that should be passed to the under