actus

0.11.1-alpha.0 • Public • Published

actus

Minimalist, boilerplate-free, framework-agnostic state container

npm version

  • Simple - it takes 2 minutes to learn
  • Boilerplate-free
    • comes with built-in default actions (set(), reset(), toggle(), merge(), etc.)
    • handles loading and error states for async actions for you
  • Framework-agnostic

Examples

React Counter App

import { actus } from "actus";
import React from "react";
import ReactDOM from "react-dom";

actus({
  state: 0,
  subscribers: [
    ({ state, actions }) => {
      ReactDOM.render(
        <>
          <h1>{state}</h1>
          <button onClick={actions.increment}>+</button>
          <button onClick={actions.decrement}>-</button>
        </>,
        document.querySelector("#root")
      );
    },
  ],
});

Try it on CodeSandbox

API

import { actus } from "actus";

// actus() returns actions bound to the current state, in case if you need them
// outside of subscribers:
const actions = actus({
  // The initial state:
  state: { number: 0 },

  // Actions accept an optional payload and the current state, and must return
  // a new state:
  actions: {
    number: {
      add: ({ state, payload }) => state + payload,
    },
  },

  // Subscribers will be called sequentially during initialization and then
  // after any action call:
  subscribers: [({ state, actions, actionName, payload }) => {}],
});

// The first argument is the payload:
actions.number.add(1);

Plugins

The following plugins are enabled automatically (but can be redefined manually if needed):

Other plugins that can be enabled manually:

Frameworks

Acknowledgements

Sources of inspiration:

Changelog

License

MIT

Package Sidebar

Install

npm i actus

Weekly Downloads

3

Version

0.11.1-alpha.0

License

MIT

Unpacked Size

25.2 kB

Total Files

16

Last publish

Collaborators

  • evgenyorekhov