@olliecaine/reducers
v1.0.19
Published
A simple tree-shakable TypeScript library boilerplate
Downloads
20
Maintainers
Readme
@olliecaine/reducers
A simple tree-shakable TypeScript library boilerplate
Stacks
- unit test: mocha, chai
- code coverage: nyc, wallabyjs(optional)
- ci: travis
How to use?
Example type-safe Redux reducer:
import { createAction } from '@olliecaine/reducers'
import { ActionsUnion, IReduxReducer } from '@olliecaine/reducers/types'
// ------------------------------------
// Action types
// ------------------------------------
enum ActionTypes {
SHOULD_INCREMENT_COUNTER = 'SHOULD_INCREMENT_COUNTER',
}
// ------------------------------------
// Action creators
// ------------------------------------
const actions = {
shouldIncrement: (incrementAmount: number) => createAction(ActionTypes.SHOULD_INCREMENT_COUNTER, incrementAmount),
}
type Actions = ActionsUnion<typeof actions>
// ------------------------------------
// State
// ------------------------------------
const initialState = 0 as number
type State = typeof initialState
// ------------------------------------
// Reducer
// ------------------------------------
const reducer = (
state = initialState,
action: Actions
): State => {
switch (action.type) {
case ActionTypes.SHOULD_INCREMENT_COUNTER:
return state + action.payload
default:
return state
}
}
// ------------------------------------
// Expose
// ------------------------------------
export const counterReducer: IReduxReducer<typeof reducer, ReturnType<typeof reducer>, typeof actions> = {
initialState,
reducer,
actions,
}
Commands list
yarn test // run test(mocha) and coverage report(nyc)
yarn test:watch // run test on watch mode (without coverage report)
yarn build // build for both esm (ES5 + ES2015 module) and ES5 UMD bundle, at dist folder.
yarn lint // run lint against lib and test
Testing
This boilerplate use Mocha as test framework.
Reference
http://blog.mgechev.com/2017/01/21/distributing-an-angular-library-aot-ngc-types
Please help
Welcome for PR
License
MIT