Skip to content

Instantly share code, notes, and snippets.

@aGuyNamedJonas
Last active April 11, 2017 15:32
Show Gist options
  • Save aGuyNamedJonas/33f6099d507ff5ad91d619035f4fc2f9 to your computer and use it in GitHub Desktop.
Save aGuyNamedJonas/33f6099d507ff5ad91d619035f4fc2f9 to your computer and use it in GitHub Desktop.
import { createSlimReduxStore } from 'slim-redux';
// Create a store with initial state = 0
var store = createSlimReduxStore(0);
// Make sure we see any store changes in the console
store.subscribe(() =>
console.log(store.getState())
)
// Register a change with the actionType 'INCREMENT' and the appropriate reducer.
// This returns a change-trigger function (see below)
const increment = store.createChangeTrigger({
actionType: 'INCREMENT',
reducer: (state, payload, action) => {
return state + payload.value;
}
});
// Note that the hereby registered reducer would also process 'DECREMENT' actions
// from the rest of your redux code.
const decrement = store.createChangeTrigger({
actionType: 'DECREMENT',
reducer: (state, payload, action) => {
return state - payload.value;
}
});
// Trigger a store-change - that is: Dispatch the action:
// {type: 'INCREMENT', payload: {value: 10}}
increment({value: 10});
increment({value: 23});
decrement({value: 31});
decrement({value: 11});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment