Skip to content

Instantly share code, notes, and snippets.

@raypulver
Created November 8, 2016 18:33
Show Gist options
  • Select an option

  • Save raypulver/41336e2118e035e6b6bf24c8f70349fb to your computer and use it in GitHub Desktop.

Select an option

Save raypulver/41336e2118e035e6b6bf24c8f70349fb to your computer and use it in GitHub Desktop.
const { create, assign } = Object,
{ dispatch, getState } = (function () {
let state = {
a: 5
};
const reduce = (last, action) => {
const { type, payload } = action;
switch (type) {
case 'INCREMENT_A':
return assign({ a: last.a + payload }, last);
}
return last;
};
}
return {
dispatch: (action) => {
state = reduce(state, action);
},
getState: () => state
};
})();
dispatch({
type: 'INCREMENT_A',
payload: 5
});
log(getState().a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment