This repository was archived by the owner on Feb 16, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork7
Immutable and type-checked state and actions for Redux
License
NotificationsYou must be signed in to change notification settings
gcanti/redux-tcomb
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Immutable and type-checked state and actions for Redux (built ontcomb library)
import{createStore,applyMiddleware}from'redux'importtfrom'tcomb'import{createCheckedMiddleware,createCheckedReducer,createActionType}from'redux-tcomb'importcreateLoggerfrom'redux-logger'// typesconstState=t.IntegerconstPositiveInteger=t.refinement(t.Integer,n=>n>=0,'PositiveInteger')constAction=createActionType({INCREMENT:t.interface({delta:PositiveInteger}),DECREMENT:t.interface({delta:PositiveInteger})})// reducerfunctionreducer(state=0,action){switch(action.type){case'INCREMENT' :returnstate+action.deltacase'DECREMENT' :returnstate-action.delta}returnstate}// configureconststore=createStore(createCheckedReducer(reducer,State),applyMiddleware(createCheckedMiddleware(Action),createLogger()))// okstore.dispatch({type:'INCREMENT',delta:2})store.dispatch(Action.INCREMENT({delta:2}))// bad payloadstore.dispatch({type:'INCREMENT',delta:-2})// throws [tcomb] Invalid value -2 supplied to Action(INCREMENT)/delta: PositiveInteger// typostore.dispatch({type:'INCRE',delta:1})// throws [tcomb] Invalid value { "type": "INCRE", "delta": 1 } supplied to Action
typeReducer=(state:State,action:Action)=>State;
createCheckedMiddleware(Action: Type) -> Function
createCheckedReducer(reducer: Reducer, State: Type) -> Reducer
createActionType(actions: {[key: string]: Type}) -> Type
The MIT License (MIT)
About
Immutable and type-checked state and actions for Redux
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.