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

redux-store

v0.0.0

Published

a redux all-in-one class for actions, stores, and state

Downloads

676

Readme

redux-store

A store/action subsystem for redux

npm status Dependency status

example

npm i redux-store

const reduxStore = require('redux-store')

api

main(arg[,opts])

install

With npm do:

npm install redux-store

Introduction

This class internalizes the store, state and action trilogy of redux in a single objects.

Actions are created off the store.addAction method, which unlike a switch based system allows for actions to be added dynamically by client processes.

Store

Store is a self contained redux-based state machine. It internalizes the state function and allows for dynamic addition of actions.

It decorates an internal redux store, exposing

  • getState
  • subscribe
  • dispatch

with all the expected behaviors from redux.

Expanded (lazy) dispatch

Dispatch accepts an object, which must have a type (string) property. It also accepts two expanded signatures:


myState.dispatch(TYPE, object);

myState.dispatch(TYPE, KEY, VALUE);

So al three of these calls have the same effect:


myState.dispatch({type: 'ADD', value: 4});
myState.dispatch('ADD', {value: 4});
myState.dispatch('ADD', 'value', 4);

Constructor

Store's constructor is the initial state. its optional; if ommitted initial state is empty object.

addAction

Store exposes

  • addAction(name, handler)

to allow for on-the-fly definitions of actions that can be dispatched. the handler is a method with the signature


(action, state) => { }

... where action is the dispatched object and state is the previous state.

Chaining

addAction and dispatch are chainable (return self) allowing:

var state = new State({value: 1});
var afterState = state.addAction('ADD', (action, state) => {value: state.value + action.value})
.dispatch('ADD', 'value', 4)
.dispatch('ADD', 'value', 6);

// afterState.value = 10;

Nesting States

States can have states as properties of their state. (I know this is a bit screwy but I can't figure out a better way to say it.)

As seen in the spec:


    var start = {
        one: new Store({value: 0}).addAction(ADD, ADD_METHOD)
    }

    var store = new Store(start);

    nestedTest.same(store.getState(), {one: {value: 0}});

    store.dispatch(`one.${ADD}`, {add: 5});

    nestedTest.same(store.getState(), {one: {value: 5}});
    

note, getState() recursively boils down any sub-properties into their current getState() values. If you want to access a property of state that is a known state, you must call myStore.getState(true) that disables this post-process.

Also, as long as you dispatch actions from the root state, all actions should alert subscribers, whether the action ultimately updates the root state or the child state. i.e.,


var dispatchCount = 0;

var start = {
    one: new Store({value: 0}).addAction(ADD, ADD_METHOD)
}

var store = new Store(start);

var u = store.subscribe(() => ++dispatchCount);

store.dispatch(`one.${ADD}`, {add: 5});

nestedTest.equal(dispatchCount, 1);

... however store.getState(true).one.dispatch('ADD', 'value', 5) would not alert any subscribers to store. This is intentional to allow local subscription to state's substates when that is a desired behavior.

dispatching to a nested state

If property 'foo' of state is a subState and it has an action 'bar', calling myState('foo.bar') will apply the action 'bar' to state.foo`.

license

MIT © David Edelhart