1.1.0 • Published 2 years ago

anotherstatemanager v1.1.0

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
github
Last release
2 years ago

StateManager.js

status downloads size lic

npm i anotherstatemanager

Simple state manager.

Set key responses to have functions fire when keyed values change. Can be set to run on a timer interval, or only fire when triggered, or you can stack sequential updates to fire per frame (e.g. summing key inputs). Very flexible, dependent on our ObjectListener.js

Example:

import {StateManager} from 'anotherstatemanager'

let state = new StateManager();

let sub = state.subscribe('x',(newx) => {console.log(newx);});




state.subscribe(key,onchange);
state.subscribeTrigger(key,onchange);
state.subsribeSequential(key,onchange);

state.unsubsribe(sub);
state.unsubscribeTrigger(sub);
state.unsubscribeSequential(sub);

state.subscribeOnce(key,onchange);
state.subscribeTriggerOnce(key,onchange);
state.subscribeSequentialOnce(key,onchange);
//...

state.setState({x:3});
state.setState({...keys:values});

There are 3 different state systems stacked on top of each other. You can set up the state manager to only use triggers (by setting defaultKeyEventLoop to false on init) which run exclusively on setState, avoiding needless timer checks. Individual subscriptions can be set to not run the checkers too, you can get pretty complicated but it's easier to keep different states with different schedules.

The rest of the functions are pretty much internal use only.

You can directly mutate state.data.x etc. which will still update the timer-check data, but will miss triggers.

The crux of this relies on a heavily modified JSON.stringifyFast function which lets you monitor large objects and arrays with a fast, shallow deep-copy system. We hammered it out to deal with giant objects or arrays etc. as lazily as possible, just watch your performance if you're also gonna be that lazy as it has a few catches.

By Joshua Brewster and Garrett Flynn License: AGPL v3.0

1.0.19

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago