Socket
Socket
Sign inDemoInstall

anotherstatemanager

Package Overview
Dependencies
1
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    anotherstatemanager

Very flexible, performant, simple state management for managing a lot of rapid changes and various scenarios. Great for low overhead event management of game inputs and data streams.


Version published
Maintainers
1
Install size
123 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 25 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc