Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

storeon-observable

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storeon-observable

RxJS based module for Storeon which allows to create async actions

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Storeon Observable

npm version Build Status

Storeon logo by Anton Lovchikov

A tiny rxjs 6-based middleware for Storeon. Compose and cancel async actions to create side effects and more.

The size is only 383 bytes. It uses Size Limit to control size.

Read more about Storeon article.

Install

Via NPM: This module has peer dependencie of rxjs@6.x.x and storeon@3.x.x which will has to be installed as well.

npm install -S storeon-observable

or

yarn add storeon-observable

Via CDN: Add the following script to the end of your <head> section.

<script src="https://unpkg.com/storeon-observable/dist/storeon-observable.min.js"></script>

The global namespace for module is StoreonObservable

Via ES Modules: Use the following import inside your ESModule.

<script type="module">
  import { createEpicModule } from 'https://cdn.pika.dev/storeon-observable'
</script>

How to use

You need to create epic using RxJS operators. This epic will listen to event ping, wait for 1 second and map them to a new event, pong

epic.js
import { combineEpics, ofEvent, toEvent } from 'storeon-observable'
import { mapTo, delay } from 'rxjs/operators'

const epic = event$ => event$.pipe(
  ofEvent('ping'),
  delay(1000),
  mapTo(toEvent('pong')),
);

export const epics = combineEpics(epic);

Create store and pass epics to the createEpicModule function. It will connect all epics to the Storeon using the storeon-observable middleware

store.js
import { createStoreon } from 'storeon'
import { createEpicModule } from 'storeon-observable'

import { epics } from './epic';

let increment = store => {
  store.on('@init', () => ({ isPinging: false }))
  store.on('ping', () => ({ isPinging: true }))
  store.on('pong', () => ({ isPinging: false }))
}

export const store = createStoreon([increment, createEpicModule(epics)]);

Using TypeScript you can assign Epic interface to the function to specify action and state typing

epic.ts
import { combineEpics, ofEvent, Epic, toEvent } from 'storeon-observable';
import { mapTo, delay } from 'rxjs/operators'

interface State {
  isPinging: boolean;
}

interface Events {
  ping: undefined;
  pong: undefined;
}

const epic: Epic<State, Events> = (event$, state$) => event$.pipe(
  ofEvent('ping'),
  delay(1000),
  mapTo(toEvent('pong')),
);

export const epics = combineEpics(epic);

Acknowledgments

This module based on redux-observable.

License

MIT

FAQs

Package last updated on 04 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc