0.9.1 • Published 4 years ago

@redux-tools/actions v0.9.1

Weekly downloads
218
License
MIT
Repository
github
Last release
4 years ago

@redux-tools/actions

An alternative to redux-actions, implemented using Ramda. Is is essentially a collection of utility functions for creating FSA-compliant action creators and reducers.

Usage

import {
	makeActionTypes,
	makeConstantActionCreator,
	makeSimpleActionCreator,
	makeActionCreator,
	makeReducer,
} from '@redux-tools/actions';
import { multiply } from 'ramda';
import { alwaysNull } from 'ramda-extension';

export const ActionTypes = makeActionTypes('duck', ['INCREMENT', 'ADD', 'CRAZY_ADD']);

export const increment = makeConstantActionCreator(ActionTypes.INCREMENT);
export const add = makeSimpleActionCreator(ActionTypes.ADD);
export const crazyAdd = makeActionCreator(ActionTypes.CRAZY_ADD, multiply(2), alwaysNull);

export default makeReducer(
	[
		[ActionTypes.INCREMENT, count => count + 1],
		[ActionTypes.ADD, (count, action) => count + action.payload],
		[ActionTypes.CRAZY_ADD, (count, action) => count + action.payload / 2],
	],
	0
);

API Reference

makeActionCreator

Creates a new unary action creator which will apply the provided functions to an argument, producing the payload and meta properties.

Arguments

  1. type (string): The action type.
  2. getPayload (any –> any): Payload getter.
  3. getMeta (any -> any): Meta getter.

Returns

(any -> Action): An action creator.

makeSimpleActionCreator

Creates a new unary action creator which will use the argument as the payload.

Arguments

  1. type (string): The action type.

Returns

(any -> Action): An action creator.

makeConstantActionCreator

Creates a new nullary action creator.

Arguments

  1. type (string): The action type.

Returns

(() -> Action): An action creator.

makeReducer

Creates a complex reducer from (type, reducer, errorReducer) tuples, akin to using the switch statement. Note that you needn't pass the default behavior.

Arguments

  1. tuples ([[string, Reducer, ?Reducer]]): Tuples to combine into a reducer. The third tuple reducer is required only if you plan to pass errors (instanceof Error) into them, otherwise you can omit it.
  2. initialState (any): Initial state for the reducer.

Returns

(Reducer): A new reducer.

0.9.1

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.5.0-alpha.4

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago