@machinat/stream

0.6.0 • Public • Published

Machinat Stream

Reactive programming stream for handling events in back-end.

This package is still on early experimental. There might be breaking changes in the future for supporting cluster. You can check the future road map here.

Install

npm install @machinat/stream
# or with yarn
yarn add @machinat/stream

Docs

Check the Reactive Programming document and the package reference.

Example

import { makeContainer, IntentRecognizer } from '@machinat/core';
import { fromApp } from '@machinat/stream';
import { map, filter } from '@machinat/stream/operators';
import app from './app';

const event$ = fromApp(app);

const textMsg$ = events$.pipe(
  filter(({ event }) => event.type === 'text'),
  map(
    makeContainer({ deps: [IntentRecognizer] })(
      (recognizer) =>
        async (context) => {
          const { channel, text } = context.event;
          const intent = await recognizer.detectText(channel, text);
          return { ...context, intent };
        }
    )
  )
);

textMsg$.subscribe(async ({ intent, reply }) => {
  const action = intent.type;
  if (action) {
    await reply(`start ${action}...`);
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i @machinat/stream

Weekly Downloads

12

Version

0.6.0

License

MIT

Unpacked Size

41.5 kB

Total Files

52

Last publish

Collaborators

  • lrills0515
  • lrills