0.0.4 • Published 1 year ago

@defx/s4 v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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>
0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago