JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44
  • Score
    100M100P100Q65041F
  • License MIT

simple state management

Package Exports

  • send-action

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (send-action) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

send-action

A simple state container.

npm

Resources

Install

npm i --save send-action

About

send-action is meant to be the smallest, simplest redux-like state management library. The focus is on providing a concise method for triggering actions, and on avoiding complex middleware & development dependencies.

The API is significantly different from redux, but the pattern is similar.

Using send-action you trigger actions, modify state based on those actions, and listen to the changes to render your application.

Minimal example

var sendAction = require('send-action')

/*
* Create send function.
*/
var send = sendAction({
  onaction: function (action, state) {
    // return a new object based on the action
    if (action.type === 'example') {
      return { example: action.value }
    }
  },
  onchange: function (action, state, oldstate) {
    // render your application
    console.log(action, state, oldstate)
  },
  state: {
    example: null
  }
})

/*
* Send an action to the store
*/
send({ type: 'example' value: 'ok' })

/*
* Alternate `send` syntax
*/
send('example', { value: 'cool' })

Using send-action with xtend

You may want to use a module like xtend to create new objects by extending the existing state.

var xtend = require('xtend')
var sendAction = require('send-action')

/*
* Create send function.
*/
var send = sendAction({
  onaction: function (action, state) {
    // return a new object based on the action using xtend
    if (action.type === 'example') {
      return xtend(state, { example: action.value })
    }
  },
  onchange: function (action, state, oldstate) {
    // render your application
    console.log(action, state, oldstate)
  },
  state: {
    example: null
  }
})

Examples with common UI modules

See also

  • choo - a frontend framework built from small modules, including send-action

License

MIT