1.8.0 • Published 3 years ago

saga-reducer-factory v1.8.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

saga-reducer-factory

A utility for minimizing boilerplate in redux + redux-saga

It's important to have the BL layer as cohesive as possible. Therefore, I think it's better to treat sagas and reducers as a single unit. This module helps us achieve that, with reduced boilerplate.

Installation

$ npm i -S saga-reducer-factory

Usage

Saga module

import SagaReducerFactory from 'saga-reducer-factory';
import { actions, types } from '../actions/loginActions';
import { put } from 'redux-saga/effects';

let {handle, updateState, saga, reducer} = SagaReducerFactory({
    actionTypes: types,
    actionCreators: actions,
    initState: {}
});

handle(types.LOGIN, function*() {
    yield put(updateState({
        loggedIn: true
    }));
});

handle(types.LOGOUT, function*() {
    yield put(updateState({
        loggedIn: false
    }));
});

handle(types.RESUME, function*() {
    yield put(updateState({
        loggedIn: true
    }));
});

export default {saga, reducer};

Actions module

import {ActionCreatorHelper} from 'saga-reducer-factory';

const actionsList = [
    'LOGIN',
    'LOGOUT',
    'RESUME'
];

export const types = ActionCreatorHelper.createTypes(actionsList, 'SESSION_');
export const actions = ActionCreatorHelper.createActions(actionsList, 'SESSION_');

Explanation

  1. updateState creates an action that updates the reducer.
  2. ActionCreatorHelper is a utility for creating actions from plain strings, by utilizing redux-actions.
1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago