typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture

MIT License

Downloads
851.8K
Stars
2.4K
Committers
28

Bot releases are hidden (Show)

typesafe-actions -

Published by piotrwitek almost 6 years ago

Removed test files from published npm bundle

typesafe-actions -

Published by piotrwitek almost 6 years ago

  • Extended isOfType to accept array of types to be consistent with isActionOf (#86)
  • Added better redux-actions compatibility for easier migration (#96)
typesafe-actions - Improved conditional types

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

typesafe-actions - Official v2.0 Release

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:

  • those who wants quickly and easily generate Discriminated Union Type from action creator module (ActionType)
  • those who likes to preserve action-creator parameters names (action & createAction)
  • those who uses Generic Interface for payload/meta arguments (createStandardAction)
  • those who wants to cut boilerplate for composite actions when handling network requests (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)

typesafe-actions - Hotfix

Published by piotrwitek over 6 years ago

  • moved tslib to deps
typesafe-actions - Hotfix 2

Published by piotrwitek almost 7 years ago

  • fixed tsconfig exclude of spec files in the npm bundle
typesafe-actions - Hotfix 1

Published by piotrwitek almost 7 years ago

  • include source files with npm package needed for various source map tooling
typesafe-actions -

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}`;
...
typesafe-actions - Production ready release

Published by piotrwitek almost 7 years ago

API is frozen with semantic versioning:

API

  • createAction
  • getType
  • isActionOf
typesafe-actions - RC1

Published by piotrwitek almost 7 years ago

New:

isActionOf

assert specific action from union type

> Advanced Usage

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 };
typesafe-actions - RC0

Published by piotrwitek almost 7 years ago

New:

  • getType - new helper method to get type of action creator in more "FP" way
// 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:

  • createAction - return action creator instance type access using getType instance method
const increment = createAction('INCREMENT');
// get action type const
expect(getType(increment)).toBe('INCREMENT');

Update:

  • added handling of few edge cases
  • added more test cases and type correctness test cases
Package Rankings
Top 1.13% on Npmjs.org
Badges
Extracted from project README
Latest Stable Version NPM Downloads NPM Downloads Bundlephobia Size Build Status Dependency Status License Join the community on Spectrum Let's fund issues in this repository