@defx/s4

0.0.4 • Public • Published

@defx/s4

A Simple redux-like UI state container


@defx/s4 is a ~350b JavaScript library consisting of...

import { configure, dispatch, subscribe, getState } from "@defx/s4"

Install via NPM

npm install @defx/s4

Import via CDN

import {
  configure,
  dispatch,
  subscribe,
  getState,
} from "https://www.unpkg.com/@defx/s4"

API

configure

function configure(
  /**
   * The reducer function will handle each action that is dispatched and return the new state
   */
  fn: Reducer,
  /**
   * (optional) An array of middleware functions that will be invoked immediately after an action is dispatched and before it is passed to the reducer.
   */
  middleware?: Middleware[]
): void

dispatch

function dispatch(
  /**
   * The name of the action
   */
  type: string,
  /**
   * An object containing any values required to update state
   */
  payload: SerialisableObject
)

subscribe

function subscribe(
  /**
   * The subscription callback will be invoked with the current state whenever the state has changed
   */
  fn: SubscriptionCallback
)

...

getState

/**
 * Returns a copy of the current state
 */
function getState(): SerialisableObject

ready

/**
 * A Promise that will resolve once the store is configured
 */
ready: Promise<void>

Readme

Keywords

none

Package Sidebar

Install

npm i @defx/s4

Weekly Downloads

3

Version

0.0.4

License

MIT

Unpacked Size

27.5 kB

Total Files

18

Last publish

Collaborators

  • defx