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

@_agco/understated

v1.0.1

Published

simple state management and caching library

Downloads

3

Readme

understated.js

A Predictable Promise based data store, caching and state management library for web and native platforms.

Usage

The library exposes simple APIs for data manipulation and management:


get(key: string OR array)

  • This method provides read-access to the state container.
  • Use it to get a snapshot of the whole state object or specific state properties by passing the key as a parameter.
  • The key parameter can either be a string or an array of keys.
  • It returns a promise, and the successful response is a snapshot of the requested data.
// Get a snapshot of the whole state container
state.get().then(state => {
  // statements
});
// Get a snapshot of a specific
// property from the state container
state.get("todos").then(todos => {
  // statements
});
// Get a snapshot of multiple
// properties from the state container
state.get(["todo1", "todo2", "todoN"]).then(todos => {
  // statements
});

update(key: string OR array: required, payload: any)

  • This method provides write-access to the state container.
  • Use it to write data in the state container.
  • The key parameter can either be a string or an array of objects ({ key, payload }) where key is required.
  • If an already existing property is passed as the key, then it gets overwritten with the new value i.e. the payload.
  • It returns a promise, and the successful response is a snapshot of the updated state.
// Add a property to the state container
state.update("amount", 10000).then(newstate => {
  // statements
});
// Add multiple properties to the state container
state
  .update([
    { key: "todo1", payload: "buy grocery" },
    { key: "todo2", payload: "dinner with mom" }
  ])
  .then(newstate => {
    // statements
  });

remove(key: string OR regex: required)

  • This method provides write-access to the state container.
  • Use it to remove one or more properties by passing the key as a parameter.
  • It returns a promise, and the successful response is a snapshot of the updated state.
// Remove a specific property
// from the state conatainer
state.remove("todo").then(newstate => {
  // statements
});

// Remove multiple properties
// from the state conatainer using regex
state.remove(/todo_i/).then(newstate => {
  // statements
});

reset()

  • This method provides write-access to the state container.
  • Use it to empty or reset the state container.
// Empty the state container
state.reset(); // returns state = {}

has(key: string: required)

  • This method provides read-access to the state container.
  • Use it to check whether a property exists in the state container.
  • It returns the value of the property if it exists, otherwise, returns false.
// Check whether a specific property
// exists in the state container
state.has("todo"); // returns {...} or false

subscribe(callback: function: required, shouldExecuteImmediately: bool)

  • This method registers a callback which will be exectued whenever the state is mutated.
  • Use this method to subscribe to state mutations.
  • shouldExecuteImmediately, if passed as true, then the callback will be immediately executed when subscribe is called.
// assign a method which will be
// called everytime the state is mutated.
state.subscribe(render);

history()

  • This method returns the history of all the state mutations since initialization.
// return the history of state mutations
state.history();