/reducer-generator-wildcard

A redux reducer-generator which builds a redux-reducer which matches against wildcards.

Primary LanguageJavaScriptMIT LicenseMIT

reducer-generator-wildcard

A reducer-generator which builds a redux-reducer which matches against wildcard types.

Under the hood this utilizes our package wildcard-utils which allows us to match strings against objects of wildcards.

Installation

yarn add reducer-generator-wildcard

or

npm install --save reducer-generator-wildcard

Simple Example

import createWildcardReducer from 'reducer-generator-wildcard'

// match any types that start with SYSTEM
const system = createWildcardReducer(
  { /* initial state */ }, 
  {
    // match any types that begin with SYSTEM
    'SYSTEM*': (state, { type, ...action }) => ({
      ...state,
      isOnline: action.isOnline !== undefined
        ? action.isOnline
        : state.isOnline,
    }),
  },
  /* You may pass extra args that will be passed to the reducer(s) */
)