npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mariosant/storeon-streams

v0.1.1

Published

Side effects management library for storeon

Downloads

8

Readme

storeon-streams

Side effects management library for storeon

NPM version Test

Why?

Reactive functional programming (RFP) can help you write complex async scenarios in a beautiful way.

You can easily write autosuggestion logic, optimistic operations and other complex async functionality without the mess.

This library can help you do that in a smooth, elegant, without having to restructure your current storeon modules. Most important, you do not have to ditch the nice async storeon's support!

Install

There is a published package at npm for easy installation. Don't forget to add kefir too, as this library depends on it!

$ npm install @mariosant/storeon-streams kefir

Quick example

Here's a side effect that triggers time/tick every second, ten times.

import { interval } from "kefir";
import { fromStoreon } from "@mariosant/storeon-streams";

const time = (store) => {
  store.on("@init", () => ({}));
  store.on("time/tick", () => {
    const today = new Date();
    const currentTime =
      today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

    return { time: currentTime };
  });

  // yeap this is it.
  fromStoreon(store, () => interval(1000, ["time/tick"]).take(10));
};

export default time;

View a more advanced example that handles optimistic save on Codesandbox.

Usage

The module has a minimal api in the form of es exports.

fromStoreon

fromStoreon is what you will be using for 90% of the time. It is responsible for connecting a kefir stream with your store.

fromStoreon(store, ({actionStream, changeStream, dispatchStream}) => Stream<[event, payload]>)

The plugin will emit actions, everytime the stream emits an event - so make sure the stream will emit only [event, payload] values.

actionStream is a kefir stream that emits when a specific action is emitted. ie actionStream('user/save')

changeStream is a kefir stream that emits when the store changes. This is using @changed event internally.

dispatchStream is a kefir stream that emits when an action is being dispatched. This is using @dispatch event internally.

Both of them are emitting the default values of storeon, wrapped in an array for easy destructuring.

fromStoreonModule

Sometimes you want a storeon module that deals only with side effects. fromStoreonModule is a wrapper that does exactly that.

const sideEffectsModule = fromStoreonModule(() =>
  interval(1000, ["time/tick"]).take(10)
);

const store = createStoreon([moduleA, moduleB, sideEffectsModule]);

isAction

When you are subscribing to dispatchStream, chances are you would like to subscribe to a specific one. isAction is a helper to do this quickly.

import { fromStoreon, isAction } from "@mariosant/storeon-streams";

fromStoreon(store, ({ dispatchStream }) =>
  dispatchStream.filter(isAction("some/action"))
);

Meta

Marios Antonoudiou – @marios_ant[email protected]

Distributed under the MIT license.

https://github.com/mariosant/storeon-streams

Contributing

  1. Fork it (https://github.com/mariosant/storeon-streams/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes using a semantic commit message.
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request