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

@imjoehaines/simple-state

v0.1.0

Published

Simple JavaScript state management

Readme

simple-state

Simple state management for JavaScript applications.

Installation

$ yarn add @imjoehaines/simple-state
# OR
$ npm install @imjoehaines/simple-state

Usage

import createStore from 'simple-state'

const initialState = { amount: 1 }

const modelConstructor = setState => ({
  increment () {
    setState(state => ({ ...state, amount: state.amount + 1 }))
  }
})

const store = createStore(initialState, modelConstructor)

console.log(store.getState()) // { amount: 1 }

store.increment()

console.log(store.getState()) // { amount: 2 }

simple-state exports a single function, createStore, which takes some initial state and a model constructor as arguments.

Initial state

The initial state of your application can be any plain JavaScript object. It's simply passed to your model when an action is called, so the structure doesn't matter to simple-state.

Model constructor

A model constructor is a function that returns a model when called. It takes a setState function as an argument and uses that inside actions to make changes to state.

Model constructors look like this

const modelConstructor = setState => ({
  increment () {
    setState(state => ({ ...state, amount: state.amount + 1 }))
  }
})

// OR

function modelConstructor (setState) {
  return {
    increment: function () {
      setState(state => ({ ...state, amount: state.amount + 1 }))
    }
  }
}

Each of the functions in the object that a model constructor returns will be available as functions on the store created by createStore. For example, in this case we would have a store.increment function as our model constructor includes this.

The setState function takes a callback which should return the updated state, based on the state argument it is provided.

Actions

An action is the name given to any function inside a model.

increment () {
  setState(state => ({ ...state, amount: state.amount + 1 }))
}

All actions will be available as functions on the store.

Listeners

The store also provides a listen function which can be used to listen for any state changes caused by actions. It accepts a callback function, which takes no arguments and will be called whenever an action is.

Any number of listeners can be attached to a store.

const store = createStore({ amount: 1 }, setState => ({
  increment () {
    setState(state => ({ ...state, amount: state.amount + 1 }))
  }
}))

store.listen(() => {
  console.log('listener one', store.getState())
})

store.listen(() => {
  console.log('listener two', store.getState())
})

store.listen(() => {
  console.log('listener three', store.getState())
})

Actions can be called from within a listener, but you should be careful not to create an infinite loop of action → listener → action.