1.0.19 • Published 1 year ago

@olliecaine/reducers v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Node.js CI Coverage Status

@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

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago