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

store-emitter

v2.2.0

Published

[![npm](https://img.shields.io/npm/v/store-emitter.svg?style=flat-square)](https://npmjs.org/store-emitter)

Downloads

9

Readme

store-emitter

npm

A simple redux-inspired state management library that provides more flexible options for listening to changes.

Example

function modifier (action, state) {
  if (action.type === 'example') {
    return { example: true }
  }
}

var store = createStore(modifier, {
  example: false
})

store.on('*', function (action, state, oldState) {
  console.log()
})

store.on('example', function (action, state, oldState) {
  t.ok(state.example)
  t.notOk(previous.example)
})

store({ type: 'example' })

API

createStoreEmitter

Create the store

Parameters

  • modifier function
  • initialState [object]

Examples

var createStore = require('store-emitter')
var store = createStore(function (action, state) {
  if (action.type === 'change_something') {
    return { something: 'changed' }
  }
})

store

Send an action to the store. Takes a single object parameter. Object must include a type property with a string value, and can contain any other properties.

Parameters

  • action object
    • action.type string

Examples

store({
  type: 'example'
  exampleValue: 'anything'
})

store.getState

Get the current state of the store

Examples

var state = store.getState()

store.initialState

Get the initial state of the store

Examples

var state = store.initialState()

store.off

Stop listening for changes to the store. Passing just the action type will remove all listeners for that action type.

Parameters

  • event string – an action type
  • callback [Function] – optional callback

Examples

store.off('article', function (action, state, oldState) {

})

store.on

Listen for changes to the store

Parameters

  • event string – an action type
  • callback Function

Examples

store.on('*', function (action, state, oldState) {

})

store.on('article', function (action, state, oldState) {

})

store.on('article:delete', function (action, state, oldState) {

})

store.once

Listen for a single change to the store

Parameters

  • event string – an action type
  • callback Function

Examples

store.once('article', function (action, state, oldState) {

})

See also

  • virtual-app – uses store-emitter as a dependency
  • namespace-emitter – is a dependency of store-emitter
  • yo-yo.js – a library for building UI components that works well with store-emitter
  • minidux – a small alternative to redux that means to be a drop-in replacement

LICENSE

MIT