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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fedeghe/pangjs

v0.0.11

Published

Lightweight asynchronous state manager

Downloads

150

Readme

PANGjs (0.0.11)

alt text

codecov

Simple asynchronous state manager

install it

> npm install @fedeghe/pangjs

define an asynchronous reducer as:

const reducer = async (oldState, action, payload) => {
    const res = await fetch(targetUrl);
    //
    // your updates 
    // 
    return newState
}

get a store and use it:

const PANGjs = require('@fedeghe/pangjs')
const store = PANGjs.getStore( reducer, initState );

// stage the results only internally
store.stage({
        type: 'ADD',
        payload: { number: 4 }
    })
    // here we get staged state
    .then(console.log);

// make all staged changes effective
store.dispatch()
    // here we get the state
    .then(console.log);

alternatively one single call just adding true as second parameter also dispatch:

store.stage({
    type: 'ADD',
    payload: { number: 4 }
}, true /* autoDispatch */) 
.then(console.log); // here we get the  state

alternatively it is possible to directly dispatch the action:

store.dispatch({
    type: 'ADD',
    payload: { number: 4 }},
)
.then(console.log); // here we get the state

API

PANGjs.getStore(reducer, initialState, config) -> store

Parameters:

  • reducer:
    the reducer function expected to have the following signature:

    (oldState, actionType, payload) => Promise

    where the returning promise resolves with the updated state.

  • initialState:
    optional object representing the initial state needed; when not provided it will be just an empty object.

  • config: this is an optional object allowing to change some default behaviors:

    • maxElements (default 1): by default no history is available, but if here we pass a number bigger than one, for example 5 then we can navigate the state back up to 5 steps using the move function to the store.
    • check (default no check): here we can pass a synchrhonous function expected to have to following signature:
      (
          state, 
          currentAction,
          previousAction,
          payload
      ) -> <Boolean>
      allowing to prevent a state change under some circumstances; that decision can be made based on the state, the ongoing currentAction which we might block, the previousAction and the current payload. Only if we return true, the reducer action will be run.

Returns:
the store instance

Throws:
[ERROR] Reducer should return something! in case the passed reducer is not a function


PANGjs.combine([reducer, ...])

Synchronous function to combine 2 or more reducers.

Parameters:

  • [reducer, ...]: two or more reducers to be combined

Returns:
the resulting combined reducer

Throws:
[ERROR] Reducer must be a function! in case one of the parameters is not a function


PANGjs.isStore(toBeChecked)

Parameters:

  • toBeChecked: what needs to be checked if it is a PANGjs store or not

store

Every store obtained invoking successfully PANGjs.getStore exposes the following:

storeInstance.getState() -> state

returns the state

storeInstance.stage(action, autoDispatch) -> Promise

stage or stage&dispatch returning a promise resolving with new state (staged or not);

Parameters:

  • action:
    {
        type: <String>,
        payload: <Object>
    }
  • autoDispatch <Boolean> default false

storeInstance.dispatch() -> Promise

dispatch all the staged changes.
Only this operations calls subscribers.

Optionally it can recieve an action and that will be equivalent to stage and dispatch:
s.stage(action).then(() => s.dispatch())
act as s.stage(action, true)
and as s.dispatch(action))

storeInstance.subscribe(fn) -> unsubscribing function

allows to register a subscribing function that will be invoked everytime the state changes (dispatched)

returns: the unsubscribing function

storeInstance.replaceReducer(fn) -> store instance

replace the store reducer

storeInstance.move(int) -> store instance

in case the history is active allows to move in the states

storeInstance.reset() -> store instance

reset the store to its initial state