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

@hacknlove/substore

v1.1.0

Published

organize your redux with substores

Downloads

2

Readme

substore

coverage 100%

Decouple your storage more and better.

install

npm i @hacknlove/substore

Api

All key can be 'deep.dotted.key'. see @hacknlove/deepobject

subStore(key)

Returns the substore at key.

If there is a substore at that key, it returns that substore. If not, it creates a new one.

The substore methods mimic the store methods.

const store = require('@hacknlove/reduxplus')
require('@hacknlove/substore')

const MySubStore1 = store.subStore('someKey')
assert(MySubstore1.i === 1)

const MySubStore2 = store.subStore('someKey')
assert(MySubstore1.i === 2)
assert(MySubStore1 === MySubStore2)

const MySubStore3 = store.subStore('otherKey')
assert(MySubStore1 !== MySubStore3)
assert(MySubstore3.i === 1)

substore.getState()

Returns the state of the substore

susbstore.setReducer(reducer)

Set a reducer to that substore, to process the actions dispatched in the substore.

substore.dispatch(action)

Dispatch an action in the substore, that will be processed by the reducers of the substore.

substore.useRedux()

React hook that refresh when the state of the substore changes.

substore.useRedux(key)

React hook that refresh when the substore's state's value at key changes.

`substore.hydrate(state, replace = false)

It set the store's state.

If replace === true, it replaces the old state with the new one. If replace !== true, it replaces the old state with the merge of the new one in the old one.

substore.subscribe(callback)

Returns a unsuscribe function.

The callback is called each time the substore's state changes, until unsuscribe funcion is called.

substore.subscribeKey(key, callback)

Returns a unsuscribe function.

The callback is called each time the substore's state's value at key changes, until unsuscribe funcion is called.

substore.clean()

If this is the last substore at its key, it removes all subscriptions, all reducers, stop all useRedux hooks and cleans all substore's substores. After that every substore method will throw new Error('subStore cleaned')

substore.clean(true)

If this is the last substore at its key, it all, including the state

substore.subStore(key)

it returns a new substore at ${substore.key}.${key} that will be cleaned when the parent substore is cleaned.

substore.setMiddleware is undefined

You cannot set a middleware to a substore.

redux DevTools

You will see the subStore actions as ºkey/type

const substore = store.subStore('foo.bar')

substore.dispatch({
  type: 'buz',
  some: {
    more: 'things'
  }
})

/*
store.dispatch({
  type: 'ºfoo.bar/buz',
  key: 'foo.bar'
  subAction: {
    type: 'buz',
    some: {
      more: 'things'
    }
  }
})
*/

asciinema

asciicast