New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

delux

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

delux

Beautiful, light and simple state manager inspired by Redux

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
increased by5.88%
Maintainers
1
Weekly downloads
 
Created
Source

Delux

Beautiful, light and simple state manager inspired by Redux

import Store from 'delux';

let store = new Store ();

store.tasks = new Store.Collection ({tasks: []});

store.tasks.on('addTask', (action, state) => state.push({
    name: action.payload,
    completed: false
}));

store.observe('tasks', (state) => console.log(state.tasks));

store.dispatch({
    type: 'addTask',
    payload: 'Try Redux'
});

Features

  • Immutable
  • Promise Based
  • Extendible classes
  • Flux Standard Actions
  • Ordered middlewares
  • No switches nor returns required

API Reference

Store

The Store holds the whole application state and it's mutation logic.

Create a Store
let store = new Store();
Description

Stores are objects whose prototype has methods to mutate there state. The Store's state is hold in Collections assigned to it.

Store instances
Properties
Store.prototype.state

Returns an object with mutations of the collections' states

Methods
Store.prototype.dispatch()

Dispatches a Flux Standard Action on the state

store.dispatch({
    type: <string | symbol>,
    payload: <object>
    error: <boolean>,
    meta: <any>
});
Store.prototype.observe()

Adds an observer for mutations in the store's collections

store.observe(['collectionName'], (state) => {

});

Parameters

  • names | name - array of collection names or a single name to observe for state mutation
  • observer - a function that with a given state mutation receives the name of the changed collection and it's new state. The arguments to the function are as follows:
NameSupplied Value
stateStore.prototype.state alias
Store.prototype.use()

Adds a middlware to the action resolution process

store.use((action) => {

});

Parameters

  • middlware - a function that mutates a given action. If it returns a Promise the store will wait for the promise to complete before passing it to the next middleware and the reducers.

Collection

Collections holds a sub-state (similar to Flux Stores) and it's mutation logic

Assign a Collection
store.collectionName = new Collection (init);

Parameters

  • init - The initial state of the collection
Collection instances
Properties
Collection.prototype.state

Returns a new mutation of the collections's state

Collection.prototype.reducers

Reflects the collections's reducers

Methods
Collection.prototype.on()

Attach a reducer to received actions (Node style)

store.collectionName.on(['actionType'], (action, state) => {

});

Parameters

  • types | type - array of action types or a single type to apply the reducer on
  • reducer - a function that with a given action mutates the collection state. The arguments to the function are as follows:
NameSupplied Value
actionThe dispatched action
stateThe collection state

Keywords

FAQs

Package last updated on 29 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc