-
Notifications
You must be signed in to change notification settings - Fork 0
WIP state management
Alexander Mextner edited this page Jan 22, 2018
·
1 revision
We're going to use Redux
config = initialState
UPD 'signal' actions don't have reducers of their own, but instead dispatch other actions.
index.js:
export { default as reducer } from './reducer'
export { actionTypes, actions } from './actions'
reducer.js:
import { getConfig } from '???'
import { actionsTypes } from './actions'
export function reducer (state = getConfig(), action) {
switch (action.type) {
case actionTypes.set: return state.set('vol', action.payload.value)
case actionTypes.increment: return state.set('vol', state.get('vol') + 1)
default return state
}
}
actions.js:
import { createActions } from '@a-x-/redux-actions';
// actionTypes: { louder: 'Vol/louder', set: 'Vol/set',,, }
// actions: 2th arg of createActions wrapped into FSA HO-functions
export const { actionTypes, actions } = createActions('Vol', {
// @phrases: 'not audibly', 'so quietly'
louder: () => {},
set: (value) => value,
// you can perform async actions, but you should avoid actions like this
weirdSyncWithDevice: async (deviceName) => (await retreiveDevice(deviceName)).volume,
// you can read state, but you should aviod it
weirdIncrement: () => (state) => state.volume + 1,
// @descr: 'make slightly loader'
increment: () => {},
})
NB. @phrases
are implicitly define actions through state description
selectors.js:
state-graphs.js (FSM state-vertices and action-edges):