npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nexustate

v1.0.46

Published

State management with listeners

Downloads

13

Readme

Description

Nexustate is designed to manage state and send notifications to listeners when state changes.

install

npm install --save nexustate

API Reference

Nexustate({ saveCallback = null, loadCallback = null, storageKey = 'default', persist = false })

parameters:

  • persist: Save and load this state? Changes will be loaded using the load() function and saved after changes occur or with the save() function
  • saveCallback: This function will be called on a throttled interval when your state changes if persist is true
  • loadCallback: 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 key

response:

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' } };

Nexustate.set(object, options = { immediatePersist: false, noNotify: false })

parameters:

  • object: Apply this object into the current state
  • options.immediatePersist: Don't throttle the save function, call it immediately. Useful for tests
  • options.noNotify: Don't send notifications to listeners

response:

Current full state

example:

state.set({ some: { key: 'hello' } }, { immediatePersist: true });

Nexustate.setKey(key, object, options = { immediatePersist: false, noNotify: false })

parameters:

  • key: String or array representing the location we want to change, this value does not have to already exist for set to work
  • object: Apply this object into the current state
  • options.immediatePersist: Don't throttle the save function, call it immediately. Useful for tests
  • options.noNotify: Don't send notifications to listeners

response:

Current full state

example:

state.setKey(['a', 'b', 'c'], 'hi');

state.get(null) // returns { a: { b: { c: 'hi' } } };

Nexustate.listen({ key: null, callback: () => {}, alias: null, component: null, transform: null, noChildUpdates: false })

parameters:

  • key: String or array for the path we want to listen for changes in
  • callback: When something changes in that path, run this callback with the new data
  • alias: Send this alias along with the change to callback
  • component: Used as a reference to remove all callbacks for a given entity using unlistenComponent
  • transform: Function to transform the incoming data before executing callback
  • noChildUpdates: Don't listen for any updates to nested child records

response:

Success boolean

example:

state.listen({ key: 'a.b.c', data => console.log , alias: 'boop', transform: value => `+++${value}` });