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 🙏

© 2025 – Pkg Stats / Ryan Hefner

statestorejs

v3.0.0

Published

A state management library for reactively and selectively updating parts of applications.

Downloads

19

Readme

statestore.js

A state management library for reactively and selectively updating parts of applications.

Installation

yarn add statestorejs

or with npm

npm install statestorejs

Go to usage in reactjs and react native apps

The basic idea behind statestore.js

Given an internal state (an object), every part of the application should be able not only to access the object
but also be able to subscribe selectively to changes made in the values of the object. The figure below shows a practical example of how statestorejs ensures selectivity in triggering change events.

In the figure below, both componnent A and B subscribes to be updated when there are changes in the values of the object. Component B does not depend on value B or changes in value B has no effect on component B therefore, never updates (or re-executed) until there's a change in value A. That is how statestorejs ensure selectivity in updates (and/or re-renders in Reactjs) applications.

Basic idea behind statestorejs

A simple demo in any JavaScript or TypeScript applications

This is a test with the usage of statestore.js to pass data from one function to the other.


import { createStore, getStore, subscribe, updateStore } from "statestorejs";

type UserInfo = { username: string, fulname: string}
function App(){
    const provider = 'storage_provider_name'
    const storename = 'store_name'
    createStore<UserInfo>(provider, storename, { username: 'KBismark', fullname: 'Bismark Yamoah'});

    //Simulates userinfo update after 2 secods
    setTimeout(() => {
        // Change username and course all subscribers listening to changes in the 'username' field
        updateStore<UserInfo>(provider, storename, {actors: ['username'], store: {username: 'KBis'}})
    }, 2000);

    // Show current user info
    ShowUserInfo()
}


// Logs user info when user info is updated in the App method
function ShowUserInfo(){
    const provider = 'storage_provider_name'
    const storename = 'store_name'
    const actualProps = getStore<UserInfo>(provider, storename);
    console.log(actualProps);

    // Performs some task
    SomeCPUIntensiveTask() 
    
    // Subscribe to changes in username only
    subscribe<UserInfo>(
        provider, storename,
        // Subscribe to the store and listen to changes in only the 'username' field
        { watch: ['username'], action: (store)=>console.log(store.username, store.fullname) }
    )
}

function SomeCPUIntensiveTask(){
    console.log('Performed some intensive task...');
}

App(); // Start app

APIs and Methods

createStore(provider, storeId, storedata)

Sets a store in a storage provider. If no storage provider with the name provider name given exists, a new storage provider with provider name given is created before the store is created.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param storedata The data to be stored

   import { createStore } from 'statestorejs'

   type User = {username: string; age: number};

   createStore<User>('some_provider', 'some_store', {username: 'John', age: 34})    

getStore(provider, storeId, cb)

Gets a copy of a store's data from a storage provider. This function returns a copy of the store if no callback is provided. If a callback is provided, then it returns the value returned by the callback. If no such store exists in the storage provider, null is returned.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param cb Optional callback that receives a copy of the store as argument if the store exists. This callback has no effect if store does not exist.

   import { getStore } from 'statestorejs'

   type User = {username: string; age: number};

   const { age, username, fullname } = getStore<User>('some_provider', 'some_store', (store)=>{
       return {...store, fullname: `${store.username}${store.age}`}
   })    

updateStore(provider, storeId, options)

Updates and trigger listners of a store data.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param options Update configuration object.

  import { updateStore } from 'statestorejs'

  type User = {username: string; age: number};

  updateStore<User>('some_provider', 'some_store', {
      actors: ['username'], // Only listeners of 'username' should be triggerd
      store: {useraname: 'James'}
  })    

subscribe(provider, storeId, options)

Subscribe to changes in a store's data or specific fields in the store. This method returns a sunscription id that can be used to unsubscribe to the service. Make sure to unsubscribe when not needed.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param options Subscription configuration object.

  import { subscribe } from 'statestorejs'

  type User = {username: string; age: number};

  const subscriptionId = subscribe<User>('some_provider', 'some_store', {
      watch: ['username'],
      action: (store)=>{
          console.log(store.username, store.age)
      }
  })    

unsubscribe(provider, storeId, subscriptionId)

Unsubscribe to changes in a store's data.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param subscriptionId The subscriptionId of the subscription to cancel.

 import { unsubscribe } from 'statestorejs'

 unsubscribe('some_provider', 'some_store', subscriptionId)    

deleteStore(provider, storeId)

Removes a store from a storage provider

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

    import { deleteStore } from 'statestorejs'

    deleteStore('some_provider', 'some_store')    

deleteProvider(provider)

Clears and removes a storage provider if exists.

@param provider Storage provider's name

   import { deleteProvider } from 'statestorejs'

   deleteProvider('some_provider')    

Usage in Reactjs and React Native

The following two methods ar specifically to be used in reactjs applications.

configureForReact(React)

Configures and setup statestorejs for use in react or react native.

    import React from 'react'
    import { configureForReact } from 'statestorejs'
    // Configure statestorejs
    configureForReact(React);    

useStateStore(provider, storeId, watch)

A react hook that takes care of subscription and unsubscriptions automatically. The hook allows components to subscribe to stores when mounted and unsubscibe when unmounted.

@param provider Storage provider's name

@param storeId Store identifier. A unique string that is used to access a store from a storage provider.

@param watch Optional array of fields to watch for changes in a store's object. When empty, [], the method only returns the store's data without any subscription. When not provided or undefined, causes component to update on changes in the value of any of the fields in the store's object.

    import React from 'react'
    import { configureForReact, createStore, useStateStore } from 'statestorejs'
    // Configure statestorejs
    configureForReact(React);   
    
    type User = {username: string; age: number};

    createStore<User>('some_provider', 'some_store', {username: 'John', age: 34})
    
    const UserDetails = ()=>{
        // Subscribes and watches the 
        const {username} = useStateStore<User>('some_provider', 'some_store', ['username']);

        return (/* ... */)
    }