JSPM

val-state

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q11941F
  • License MIT

State management with value-enhancer.

Package Exports

  • val-state
  • val-state/dist/index.js
  • val-state/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (val-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

val-state

Build Status npm-version Coverage Status minified-size

Commitizen friendly Conventional Commits code style: prettier

State management with value-enhancer.

Install

npm add val-state value-enhancer

Usage

import { createStore } from "val-state";

const store$ = createStore({
  count: 0,
});

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

Create store with actions:

import { createStore } from "val-state";

const store$ = createStore(
  {
    count: 0,
  },
  state$ => ({
    increment: (step = 1) => {
      state$.set({ count: state$.value.count + step });
    },
  })
);

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

store$.act.increment();

Assign actions to normal val:

import { val } from "value-enhancer";
import { assignActions } from "val-state";

const state$ = val({ count: 1 });

const store$ = assignActions(state$, {
  increment: (step = 1) => {
    state$.set({ count: state$.value.count + step });
  },
});

assert(store$ === state$);

store$.act.increment();