0.3.5 • Published 4 years ago

@tmorin/cycle-actions v0.3.5

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@tmorin/cycle-actions

npm version Integration api

A Cycle.js driver to manage actions.

An action is an object defined by:

  • a type
  • an optional payload
  • an optional category

The action is handled by an action handler. It's a function taking the action as argument and providing an optional response.

import xs, {Stream} from 'xstream';
import run from '@cycle/run';
import {makeActionsDriver, ActionsSource, Action} from '@tmorin/cycle-actions';

interface MainSources {
  ACTIONS: ActionsSource
}

interface MainSinks {
  ACTIONS: Stream<Action>
}

function main(sources: MainSources) : MainSinks {
  sources.ACTIONS.select('hello').result$.subscribe({
      next(result) {
        // display 'Hello Toto!' in the console
        console.log(result.response);
      }
    });
  return  {
    ACTIONS: xs.of({
      type: 'anAsyncAction',
      payload: 'Toto',
      category: 'hello'
    })
  }
}

const drivers = {
  ACTIONS: makeActionsDriver({
    async anAsyncAction(action: Action<string>) {
      // action is
      return `Hello ${action.payload}!`
    }
  })
};

run(main, drivers);
0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.1.0-alpha.2

5 years ago

0.1.0-alpha.1

5 years ago

0.1.0-alpha.0

5 years ago