0.0.12 • Published 1 year ago

typescript-fsa-factory v0.0.12

Weekly downloads
13
License
MIT
Repository
-
Last release
1 year ago

typescript-fsa-factory

Smart action factory. Based on axios and typescript-fsa.

Why?

The package implements the "smart thresher" approach and takes most of the routine work of writing template code.

Usage

import actionsFactory from 'typescript-fsa-factory';

const API_ENDPOINTS = {
  FOO: '/foo',
  BAR: '/bar',
} as const;

type ApiEndpoints = typeof API_ENDPOINTS;

const {
  // Exported from `typescript-fsa`.
  // See `typescript-fsa` documentation.
  actionCreator,
  actionCreatorAsync,

  // Smart action creator
  actionCreatorAsyncWithHandler,
} = actionsFactory<ApiEndpoints>(API_ENDPOINTS);

const actions = {
  foo: actionCreatorAsyncWithHandler<
    Actions.api.foo.started,
    Actions.api.foo.done,
    Actions.api.foo.failed
  >({
    url: API_ENDPOINTS.FOO,
    method: 'GET',
  }),

  bar: actionCreatorAsyncWithHandler<
    Actions.api.bar.started,
    Actions.api.bar.done,
    Actions.api.bar.failed
  >({
    url: API_ENDPOINTS.BAR,
    method: 'POST',
  }),
};
0.0.12

1 year ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

3 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago