piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 98 forks source link

Update docs to reflect new API #25

Closed piotrwitek closed 6 years ago

piotrwitek commented 6 years ago

Update the "tutorial" section in Readme to provide examples with new API.

piotrwitek commented 6 years ago

I was reflecting for a while on a new API and I decided to use this (it's almost ready to deploy on the next branch):

// docs example
const deprecatedApi = createActionDeprecated('GET_TODO',
  (token: string, id: string) => ({
    type: 'GET_TODO',
    payload: id,
    meta: token,
  })
);

const getTodoSimple = (token: string, id: string) => action('GET_TODO', id, token);

const getTodoVariadic = createAction('GET_TODO', actionCallback => {
  return (id: string, token: string) => actionCallback(id, token);
});

const getTodoPayload = createStandardAction('GET_TODO')<{ id: string, token: string }>();

const getTodoPayloadMap = createStandardAction('GET_TODO').map(
  ({ token, id }: { token: string; id: string }) => ({
    payload: id,
    meta: token,
  })
);

const getTodoAsync = createAsyncAction(
  'GET_TODO_REQUEST',
  'GET_TODO_SUCCESS',
  'GET_TODO_FAILURE'
)<{ token: string; id: string }, Todo, Error>();
piotrwitek commented 6 years ago

Get ready folks, official release tomorrow!