Coder Social home page Coder Social logo

aggre / reactive-store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lacolaco/reactive-store

0.0 2.0 0.0 52 KB

A store implementation for state management with RxJS

Home Page: https://yarn.pm/@lacolaco/reactive-store

License: MIT License

JavaScript 9.45% TypeScript 90.55%

reactive-store's Introduction

@lacolaco/reactive-store

A store implementation for state management with RxJS

https://yarn.pm/@lacolaco/reactive-store

Install

$ npm i rxjs @lacolaco/reactive-store 

Concept

  • RxJS-based: Use the ecosystem
  • TypeScript: Type-safe state management
  • Simple: Easy to understand what the library does and doesn't
  • Extensible: Easy to use your middlewares

Adapters

How to Use

Create a store

import { Store } from '@lacolaco/reactive-store';

const store = new Store('initialState');
assert.ok(store.getValue() === 'initialState');

store.patch(state => 'updated!');
assert.ok(store.getValue() === 'updated!');

Subscribe state's observable

import { Store } from '@lacolaco/reactive-store';

const store = new Store('initialState');

store.subscribe(state => {
  console.log(state);
});

store.patch(state => 'updated!');

Select a scoped state

import { Store } from '@lacolaco/reactive-store';

const store = new Store({ count: 0 });

const count$ = store.select(state => state.count);
count$.subscribe(count => {
  console.log(count);
});

store.patch(state => {
  return {
    count: state.count + 1,
  };
});

Middleware: Intercept dispatching

import { Store, StateHandler, Middleware } from '@lacolaco/reactive-store';

const loggingMiddleware: Middleware = (next: StateHandler): StateHandler => {
  return (state: any) => {
    const newState = next(state);
    console.log(`[State]`, newState);
    return newState;
  };
};

const store = new Store(0, [loggingMiddleware]);

reactive-store's People

Contributors

lacolaco avatar

Watchers

James Cloos avatar aggre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.