Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Nexustate is designed to manage state and send notifications to listeners when state changes.
npm install --save nexustate
parameters:
persist
: Save and load this state? Changes will be loaded using the load()
function and saved after changes occur or with the save()
functionsaveCallback
: This function will be called on a throttled interval when your state changes if persist is trueloadCallback
: This function is called when the load()
function is called, load()
must be called manually unless using getNexustate()
storageKey
: When calling the saveCallback
and loadCallback
, this key is the root keyresponse:
New instance of Nexustate
example:
import { Nexustate } from 'nexustate';
const saveState = {};
const state = new Nexustate({ saveCallback: (key, value) => { saveState[key] = value; }, loadCallback: (key) => saveState[key] });
const logChange = (data) => console.log;
state.listen({ key: ['some', 'key'], callback: logChange });
state.set({ some: { key: 'hello' } });
// logChange is called with the value 'hello'
// saveState['default'] is changed to { some: { key: 'hello' } };
parameters:
object
: Apply this object into the current stateoptions.immediatePersist
: Don't throttle the save function, call it immediately. Useful for testsoptions.noNotify
: Don't send notifications to listenersresponse:
Current full state
example:
state.set({ some: { key: 'hello' } }, { immediatePersist: true });
parameters:
key
: String or array representing the location we want to change, this value does not have to already exist for set to workobject
: Apply this object into the current stateoptions.immediatePersist
: Don't throttle the save function, call it immediately. Useful for testsoptions.noNotify
: Don't send notifications to listenersresponse:
Current full state
example:
state.setKey(['a', 'b', 'c'], 'hi');
state.get(null) // returns { a: { b: { c: 'hi' } } };
parameters:
key
: String or array for the path we want to listen for changes incallback
: When something changes in that path, run this callback with the new dataalias
: Send this alias along with the change to callbackcomponent
: Used as a reference to remove all callbacks for a given entity using unlistenComponenttransform
: Function to transform the incoming data before executing callbacknoChildUpdates
: Don't listen for any updates to nested child recordsresponse:
Success boolean
example:
state.listen({ key: 'a.b.c', data => console.log , alias: 'boop', transform: value => `+++${value}` });
FAQs
State management with listeners
The npm package nexustate receives a total of 5 weekly downloads. As such, nexustate popularity was classified as not popular.
We found that nexustate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.