const redux = require('redux');
const createStore = redux.createStore;
function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
case 'DOUBLE':
return state * 2;
case 'HALVE':
return state / 2;
default:
return state
}
}
let store = createStore(counter)
store.subscribe(() => console.log(store.getState()))
store.dispatch({ type: 'INCREMENT' })
store.dispatch({ type: 'INCREMENT' })
store.dispatch({ type: 'DECREMENT' })
Above you'll see a basic example using a standard redux-y style flow.
Below now we define the Pine middleware, which allows for events to beget other events. This is similar to elm how Commands can fire other Commands in the Update function.