Skip to content

Instantly share code, notes, and snippets.

@tadjik1
Created July 22, 2015 12:55
Show Gist options
  • Save tadjik1/db46a0de49eb448cbf4f to your computer and use it in GitHub Desktop.
Save tadjik1/db46a0de49eb448cbf4f to your computer and use it in GitHub Desktop.
implement custom subscription on redux store
const initialTodosState = [];
const initialCounterState = 0;
function todos(state = initialTodosState, action) {
return state;
}
function counter(state = initialCounterState, action) {
return state;
}
const reducer = combineReducers({ todos, counter }});
const store = createStore(reducer);
// right now my store structure looks like:
// store.getState() =>
// {
// todos: [...],
// counter: 0
// }
// how could I subscribe on update only `todos` subtree or `counter`?
@tadjik1
Copy link
Author

tadjik1 commented Jul 22, 2015

the default method store.subscribe(handler) allows to sibscribe only on root (my handler will be invoked after every changes, counter and todos)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment