typeless

typeless

  • Docs
  • API
  • Github

›API Reference

Introduction

  • Quick Start
  • Motivation
  • Examples
  • Starters Kits
  • Roadmap

Using typeless

  • HMR
  • Code-Splitting

API Reference

  • createModule
  • createSelector
  • useActions
  • useMappedState
  • useSelector
  • ChainedReducer
  • Epic
  • Handle
  • Rx

API Reference (router)

  • createUseRouter
  • RouterActions
  • getRouterState
  • Link

API Reference (form)

  • createForm
  • FormActions

Rx

Rx is a convenience re-export of rxjs. Check this issue for motivation.

The entry point contains:

  • all exports from rxjs/operators
  • Following exports from rxjs:
    Subject, forkJoin, empty, of, timer, from, defer, Observable, interval
  • Renamed exports from rxjs:
    • concat -> concatObs
    • merge -> mergeObs
    • race -> raceObs
    • throwError -> throwObs
  • Following exports from rxjs/internal-compatibility:
    fromPromise

Additional operators

ofType(actionCreator)

Filter actions based on the provided action creator or action creators.

Arguments

  1. actionCreator: AC | AC[] - the action creator or array of action creators.

Returns

{OperatorFunction} - the rxjs operator function.

Example

// symbol.ts
export const MySymbol = Symbol('my');

// interface.ts
import { createModule } from 'typeless';
import { MySymbol } from './symbol';

export const [handle, MyActions] = createModule(MySymbol)
  .withActions({
    loadUser: null,
    userLoaded: (user: User) => ({ payload: { user } }),
    cancel: null,
  });

// module.ts
import * as Rx from 'typeless/rx';
import { handle, MyActions } from 'typeless';

handle.epic()
  .on(MyActions.loadUser, (_, { action$ }) =>
    API.loadUser().pipe(
      Rx.map(user => MyActions.userLoader(user)),
      // cancel operation if `MyActions.cancel()` is dispatched
      Rx.takeUntil(action$.pipe(Rx.ofType(MyActions.cancel)))
    )
  );

waitForType(actionCreator)

Wait for a single action creator.

Arguments

  1. actionCreator: AC - the action creator to wait for.

Returns

{OperatorFunction} - the rxjs operator function.

Example

// symbol.ts
export const MySymbol = Symbol('my');

// interface.ts
import { createModule } from 'typeless';
import { MySymbol } from './symbol';

export const [handle, MyActions] = createModule(MySymbol)
  .withActions({
    deleteUser: null,
    userDeleted: null,
    errorOccurred: null,
    confirmDelete: (confirm: boolean) => ({ payload: { confirm } }),
  });

// module.ts
import * as Rx from 'typeless/rx';
import { handle, MyActions } from 'typeless';

handle.epic()
  // show a confirmation dialog and wait for Yes/No click
  .on(MyActions.deleteUser, (_, { action$ }) =>
    action$.pipe(
      Rx.waitForType(MyActions.confirmDelete),
      Rx.filter(action => action.payload.confirm)
      Rx.mergeMap(() => API.deleteUser()),
      Rx.mapTo(MyActions.userDeleted()),
      Rx.catchError(e => {
        console.error(e);
        return Rx.of(MyActions.errorOccurred());
      })
    )
  );
← HandlecreateUseRouter →
  • Additional operators
    • ofType(actionCreator)
    • waitForType(actionCreator)
typeless
Docs
Getting StartedAPI Reference
Community
Spectrum
More
GitHub
Copyright © 2020 Łukasz Sentkiewicz