0.0.12 • Published 4 years ago

redux-duplicator v0.0.12

Weekly downloads
12
License
MIT
Repository
-
Last release
4 years ago

Concept

Genrate reducers and actionCreators from their templates.

See https://redux.js.org/recipes/structuring-reducers/reusing-reducer-logic .

This has not been launched. Develoment is undertaking now.

Usage

import duplicateRedux from '../src/redux-duplicator'
import { createAction, handleActions } from 'redux-actions' // Optional

const initialState = {
  id: ''
}

const _actionTypes = {
  SET_ID: `SET_ID`
}

const setId = createAction(_actionTypes.SET_ID, (payload: string) => payload)

const _actionCreators = {
  setId
}

const id = handleActions(
  {
    [_actionTypes.SET_ID]: (state, { payload }: ReturnType<typeof _actionCreators['setId']>) =>
      payload!
  },
  initialState.id
)

const nameSpace = 'TEST/'

const { reducer, actionTypes, actionCreators } = duplicateRedux(nameSpace, {
  reducer: id,
  actionTypes: _actionTypes,
  actionCreators: _actionCreators
})

describe('actionTypes Test', () => {
  it('rewrite action types', () => {
    expect(actionTypes.SET_ID === 'TEST/SET_ID').toBeTruthy()
  })
})

describe('Reducer Test', () => {
  it('rewrite reducer match', () => {
    const result = reducer('', { type: 'TEST/SET_ID', payload: 'fuga' })
    expect(result).toEqual('fuga')
    const miss = reducer('initital', { type: 'SET_ID', payload: 'fuga' })
    expect(miss).toEqual('initital')
  })
})

describe('actionCreators Test', () => {
  it('rewrite actionCreators type', () => {
    const type = actionCreators.setId('test').type
    expect(type).toEqual('TEST/SET_ID')
  })
})
0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.0

5 years ago