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

stonix

v0.0.7

Published

Zero-configuration store for React. One API rule them all

Downloads

2

Readme

stonix

Zero-configuration store for React. One API rule them all.

Basic Example

The whole state of your app that is stored in an object tree inside a single store. The only way to change the state tree is to emit an action, an object describing what happened. To specify how the actions transform the state tree, you write pure reducers.

That's it!

import stonix from "stonix";

const storeLogic = {
  // default value for count state
  state: {
    count: 0,
  },
  "@count": {
    increase: (value) => value + 1,
    decrease: (value) => value - 1,
  },
};

// Create a store holding the your app state and logic.
// Its API is { on, call, get, ... autoGeneratedActionDispatchers }.
const store = stonix(storeLogic);
store.on(() => console.log(store.get()));
// The only way to mutate the internal state is to dispatch an action.
// increase is auto generated action dispatcher
store.increase();
// 1
store.increase();
// 2
store.increase();
// 3
// store.increase equivalence to store.call('increase')

Alternative store logic

const storeLogic = {
  // default value for count state
  state: {
    count: 0,
  },
  // action listeners
  // increase action
  increase: {
    // name of state to mutate
    count: (value) => value + 1,
  },
  // decrease action
  decrease: { count: (value) => value - 1 },
};

Structure of store logic

A store logic is plain of object following structure below

const storeLogic = {
  // indicate default value of store state
  state: {
    count: 1,
    todos: [],
  },
  // define init effect, this effect will be called when the logic applied to store
  init() {},
  // define reducer of count state, this reducer will be called whenver any action called
  "@count"(
    /* count value */ value,
    { action, payload, /* store state */ state }
  ) {
    return value;
  },
  // define increase reducer, this reducer will be called whenever increase action called
  increase: {
    // increase reducer mutates count state only
    count: (value) => value + 1,
    // can define more mutationss here
  },
  // increaseAsync is an effect, can handle asynchronous flow inside effect
  // the effect works like redux-thunk but it is easier to use
  async increaseAsync(payload, { call, delay, get }) {
    // access count state
    console.log(get().count);
    // delay is util func that returns a promise
    await delay(1000);
    // call increase action
    call("increase");
  },
  // can use wildcard "*" in effect name pattern, this means the effect will be called whenerver any action called
  "*"(payload, { action }) {
    console.log(action, payload);
  },
  // we can use wildcard for reducer or effect name pattern
  // this effect will be called whenever increase or decrease action called
  "increase|decrease"() {},
  // "starts with" wildcard
  "load_*"() {},
  // "ends with" wildcard
  "*_success"() {},
};