Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 485 Bytes

README.md

File metadata and controls

25 lines (16 loc) · 485 Bytes

State

Install

npm i -S @thepassle/app-tools

Usage

import { State } from '@thepassle/app-tools/state.js'; 

const state = new State();

/** Or pass a default state */
const state = new State({foo: 'foo'});

state.setState({foo: 'bar'}); // state === {foo: 'bar'}
state.setState((old) => ({...old, bar: 'bar'})); // state === {foo: 'bar', bar: 'bar'}

state.addEventListener('state-changed', ({state}) => {});

state.getState(); // {foo: 'bar', bar: 'bar'};