typesafe-actions

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

MIT License

Downloads
851.8K
Stars
2.4K
Committers
28

Bot releases are visible (Hide)

typesafe-actions - Latest Release

Published by piotrwitek almost 5 years ago

Breaking changes

  1. In v5 all the deprecated v4 creator functions are available under deprecated named import to help with incremental migration.
// before
import { createAction, createStandardAction, createCustomAction } from "typesafe-actions"

// after
import { deprecated } from "typesafe-actions"
const { createAction, createStandardAction, createCustomAction } = deprecated;
  1. createStandardAction was renamed to createAction and .map method was removed in favor of simpler redux-actions style API.
// before
const withMappedPayloadAndMeta = createStandardAction(
  'CREATE_STANDARD_ACTION'
).map(({ username, message }: Notification) => ({
  payload: `${username}: ${message}`,
  meta: { username, message },
}));

// after
const withMappedPayloadAndMeta = createAction(
  'CREATE_STANDARD_ACTION',
  ({ username, message }: Notification) => `${username}: ${message}`, // payload creator
  ({ username, message }: Notification) => ({ username, message }) // meta creator
)();
  1. v4 version of createAction was removed. I suggest to refactor to use a new createAction as in point 2, which was simplified and extended to support redux-actions style API.
// before
const withPayloadAndMeta = createAction('CREATE_ACTION', resolve => {
  return (id: number, token: string) => resolve(id, token);
});

// after
const withPayloadAndMeta = createAction(
  'CREATE_ACTION',
  (id: number, token: string) => id, // payload creator
  (id: number, token: string) => token // meta creator
})();
  1. createCustomAction - API was greatly simplified, now it's used like this:
// before
const add = createCustomAction('CUSTOM', type => {
  return (first: number, second: number) => ({ type, customProp1: first, customProp2: second });
});

// after
const add = createCustomAction(
  'CUSTOM',
  (first: number, second: number) => ({ customProp1: first, customProp2: second })
);
  1. AsyncActionCreator should be just renamed to AsyncActionCreatorBuilder.
// before
import { AsyncActionCreator } from "typesafe-actions"

//after
import { AsyncActionCreatorBuilder } from "typesafe-actions"

New

  • Rewrite and simplify createAction & createAsyncAction API (#192)

Improvements

  • Fixed .npmignore. Fixed #205
  • Rollup build improvements (#203)
  • Updated AsyncActionCreatorBuilder and AsyncAction types to fix cancel handler type being never (#194)
  • Fixed high memory consumption (#171)
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Downgrade rollup ver to fix react-native prod runtime error #170
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Resolved #164
  • Added performance tests: npm run performance:[2,10,50]
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Updated build pipeline to use babel for code transformation and bundle optimizations #155
typesafe-actions -

Published by piotrwitek over 5 years ago

New API

  • Added new type AsyncActionCreator (#148)
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Removed implicit dependency on tslib (Resolved #147)
typesafe-actions -

Published by piotrwitek over 5 years ago

New API

  • Added optional cancel action to the createAsyncAction API (#146)
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Updated createReducer handlers property type to show the correct type of only already added handlers
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Fixed error - createReducer cannot be called when handling more than 2 actions #145
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Fixed error - no exported member RootAction #141
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Added typing support for reducer as object map #140
typesafe-actions -

Published by piotrwitek over 5 years ago

New API

  • Added createReducer a typesafe reducer factory using object map and chain API #106
  • Exported various helper-types returned from public API #123
typesafe-actions -

Published by piotrwitek over 5 years ago

Breaking change

From v4.x.x all action creators will use undefined instead of void as a generic type parameter to make the action-creator function require NO parameters.

Background discussion: https://github.com/piotrwitek/typesafe-actions/issues/124#issuecomment-479446603

const increment = createStandardAction('INCREMENT')<undefined>();
increment(); // <= no parameters required

const fetchUsers = createAsyncAction(
  'FETCH_USERS_REQUEST',
  'FETCH_USERS_SUCCESS',
  'FETCH_USERS_FAILURE'
)<undefined, User[], Error>();
fetchUsers.request(); // <= no parameters required
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

  • Improved ActionType to bring back v3.3 behaviour #132
  • Fixed backward compatibility for void type parameters from v3.1 (after internal type refactoring for v3.2 they were not treated as EmptyAC anymore) #124
typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

Updated types to be compatible with the recent TypeScript release v3.4.1 🎉

typesafe-actions -

Published by piotrwitek over 5 years ago

New API

action and createAction have new 3rd parameter which is error property on action object making it fully FSA compliant.

import { action, createAction } from 'typesafe-actions';

export const todosError = (message: string) => action('todos/ERROR', message, undefined, true);
// todosError: (message: string) => { type: "todos/ADD"; payload: string; error: boolean; }

export const todosError = createAction('todos/ERROR', action => {
  // Note: "action" callback does not need "type" parameter
  return (message: string) => action(message, undefined, true);
});
// todosError: (message: string) => { type: "todos/ADD"; payload: string; error: boolean; }

Improvements

Fixed #117
Fixed #118

typesafe-actions -

Published by piotrwitek over 5 years ago

Improvements

Fixed #122

typesafe-actions -

Published by piotrwitek over 5 years ago

New API

createCustomAction

Create an enhanced action-creator with unlimited number of arguments and custom properties on action object.

  • Arguments of resulting action-creator will preserve their original semantic names (id, firstName, lastName).
  • Returned action objects have custom properties ({ type, customProp1, customProp2, ...customPropN })
createCustomAction(type, type => {
  return (namedArg1, namedArg2, ...namedArgN) => ({ type, customProp1, customProp2, ...customPropN })
})

Examples:
> Advanced Usage Examples

import { createCustomAction } from 'typesafe-actions';

const add = createCustomAction('CUSTOM', type => {
  return (first: number, second: number) => ({ type, customProp1: first, customProp2: second });
});

add(1) // { type: "CUSTOM"; customProp1: number; customProp2: number; }
typesafe-actions -

Published by piotrwitek almost 6 years ago

Breaking change

From v3.x.x the minimum required TS version is v3.2.

This allow us to benefit from new type-checker features like tuple types and to simplify some existing complexity in function overloads.
This should help us in the long run to implement new features faster.

typesafe-actions -

Published by piotrwitek almost 6 years ago

FIXED:

Resolved #68
Resolved #53
Resolved #91
Resolved #44
Resolved #74
Resolved #77
Resolved #100
Resolved #42