stuffit
TypeScript icon, indicating that this package has built-in type declarations

0.5.5 • Public • Published

!! Documentation work in progress !!

Description

Observable state stores with a set of operators and producers. The stores behave like hot observables. They can be eager or lazy.

Synopsis

Example using the stores as observables

import * as Stuffit from 'stuffit';
 
const jsonData$ = Stuffit.Producers
    .fromInterval(5000)
    .pipe(Stuffit.Operators.map(async () => {
        const response = await fetch('http://example.org/file.json');
        const data = await response.json();
        return data;
    }))
    .pipe(Stuffit.Operators.map(Stuffit.Producers.fromPromise))
    .pipe(Stuffit.Operators.flatten);
 
const subscription = jsonData$.subscribe(console.log);
 
// Later, clean up the subscription...
subscription.unsubscribe();

Example using the stores as state containers

import * as Stuffit from 'stuffit';
 
// Initialize with 0.
const counterStore = new Stuffit.PushStore(0);
// Increment the state. Side note: the observable part of the store will emit a new event.
counterStore.setState(counterStore.state + 1);
console.log(counterStore.state); // "1" is logged.

Example creating your own store

import * as Stuffit from 'stuffit';
 
class CounterStore extends Stuffit.PushStore<number> {
    public constructor() {
        super(0);
    }
 
    public increment() {
        this.setState(this.state + 1);
    }
 
    public decrement() {
        this.setState(this.state - 1);
    }
 
    public reset() {
        this.setState(0);
    }
}
 
const counterStore = new CounterStore();
const subscription = counterStore.subscribe(console.log);
counterStore.increment(); // "1" is logged.
counterStore.increment(); // "2" is logged.
counterStore.reset(); // "0" is logged.

Documentation

In the world of stores we can think of data flowing to and from three different kind of objects:

  • Producers: they create data and consume none.
  • Operators: they take data from one or more source stores and transform it into new data.

Classes

Operators

Producers

Usage with other libraries

Stuffit can be used to save the state of your application and it is agnostic of the frameworks you use. In principle you have the responsibility to connect the stores to your application. To make things easy however you can use some existing "plugins" to do the work for you:

Readme

Keywords

none

Package Sidebar

Install

npm i stuffit

Weekly Downloads

2

Version

0.5.5

License

Apache-2.0

Unpacked Size

105 kB

Total Files

82

Last publish

Collaborators

  • woutervh-