[![Node.js CI](https://github.com/olivercaine/typescript-library-boilerplate/actions/workflows/node.js.yml/badge.svg)](https://github.com/olivercaine/typescript-library-boilerplate/actions/workflows/node.js.yml)
[![Coverage Status](https://coveralls.io/repos/github/goldenbearkin/typescript-library-boilerplate/badge.svg?branch=master)](https://coveralls.io/github/goldenbearkin/typescript-library-boilerplate?branch=master)

# @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](http://blog.mgechev.com/2017/01/21/distributing-an-angular-library-aot-ngc-types/)

# Please help

Welcome for PR

# License

MIT