Typesafe utilities for "action-creators" in Redux / Flux Architecture
MIT License
Bot releases are hidden (Show)
Published by piotrwitek over 6 years ago
Improved types for scenarios when user wants to create actions with meta
property but without payload
property.
https://github.com/piotrwitek/typesafe-actions/issues/43
Published by piotrwitek over 6 years ago
Added a bunch of new API to cover 95% of common use-cases people encounter while working with Redux Action Creators in TypeScript:
ActionType
)action
& createAction
)createStandardAction
)createAsyncAction
)There was also internal refactoring, added lots of new test cases for runtime and types, and improved build process using Rollup, which generates nice bundles for different build workflows (commonjs, es-modules, amd for browser)
Published by piotrwitek over 6 years ago
Published by piotrwitek almost 7 years ago
Published by piotrwitek almost 7 years ago
(#8) - enhanced isActionOf to accept array of actions
// multiple actions
const logTodoAction: Epic<RootAction, RootState> =
(action$, store) => action$
.filter(isActionOf([addTodo, toggleTodo]))
.switchMap((action) => { // action is asserted as: { type: "ADD_TODO", payload: string } | { type: "TOGGLE_TODO", payload: string }
const log = `Dispatched action: ${action.type}`;
...
Published by piotrwitek almost 7 years ago
API is frozen with semantic versioning:
API
createAction
getType
isActionOf
Published by piotrwitek almost 7 years ago
New:
assert specific action from union type
function isActionOf(actionCreator: AC<T>): (action: A<T>) => action is T
// AC<T> extends (...args: any[]) => A<T>
Examples:
import { addTodo } from './actions';
// in epics
const addTodoToast: Epic<RootAction, RootState> =
(action$, store) => action$
.filter(isActionOf(addTodo))
.concatMap((action) => { // action is asserted as addTodo Action Type
const toast = { text: action.payload };
Published by piotrwitek almost 7 years ago
New:
// function getType(actionCreator: AC<T>): T
import { createAction, getType } from 'typesafe-actions';
const increment = createAction('INCREMENT');
const type: 'INCREMENT' = getType(increment);
expect(type).toBe('INCREMENT');
// in reducer
switch (action.type) {
case getType(increment):
return state + 1;
default: return state;
}
Change:
const increment = createAction('INCREMENT');
// get action type const
expect(getType(increment)).toBe('INCREMENT');
Update: