Nocturnal Pumpkin Maelstrom
Miss any of our Open RFC calls?Watch the recordings here! »

redux-scoped-actions

0.0.0 • Public • Published

redux-scoped-actions

build status

Namespacing utilities for redux-actions.

Why

People asked for this in redux-actions, but we didn't want to include it in core.

Install

$ npm i --save redux-scoped-actions

If you don’t use npm, you may grab the latest UMD build from unpkg (either a development or a production build). The UMD build exports a global called window.ReduxScopedActions if you add it to your page via a <script> tag. We don’t recommend UMD builds for any serious application, as most of the libraries complementary to Redux are only available on npm.

Usage

Basic example

```js import namespaceActions from 'redux-scoped-actions'

const actionCreators = namespaceActions( createActions({ 'APP/COUNTER/INCREMENT': amount => ({amount}), 'APP/COUNTER/DECREMENT': amount => ({amount: -amount}), 'APP/NOTIFY': (username, message) => ({message: ${username}: ${message}}), LOGIN: username => ({username}), }, 'LOGOUT') )

expect(actionCreators.app.counter.increment(1)).to.deep.equal({type: 'APP/COUNTER/INCREMENT', amount: 1}) expect(actionCreators.app.counter.decrement(1)).to.deep.equal({type: 'APP/COUNTER/DECREMENT', amount: -1}) expect(actionCreators.app.notify('yangmillstheory', 'Hello, World!')).to.deep.equal({ type: 'APP/NOTIFY', message: 'yangmillstheory: Hello, World!', }) expect(actionCreators.login('yangmillstheory')).to.deep.equal({ type: 'LOGIN', payload: {username: 'yangmillstheory'}, }) expect(actionCreators.logout()).to.deep.equal({type: 'LOGOUT'})

  </p>
</details>

<details>
  <summary>Destructured</summary>
  <p>
```js
import namespaceActions from 'redux-scoped-actions'

const {
  app: {
    counter: { increment, decrement },
    notify,
  },
  login, logout,
} = namespaceActions(
  createActions({
    'APP/COUNTER/INCREMENT': amount => ({amount}),
    'APP/COUNTER/DECREMENT': amount => ({amount: -amount}),
    'APP/NOTIFY': (username, message) => ({message: `${username}: ${message}`}),
    LOGIN: username => ({username}),
  }, 'LOGOUT')
)

expect(increment(1)).to.deep.equal({type: 'APP/COUNTER/INCREMENT', amount: 1})
expect(decrement(1)).to.deep.equal({type: 'APP/COUNTER/DECREMENT', amount: -1 })
expect(notify('yangmillstheory', 'Hello, World!')).to.deep.equal({
  type: 'APP/NOTIFY',
  message: 'yangmillstheory: Hello, World!',
})
expect(login('yangmillstheory')).to.deep.equal({
  type: 'LOGIN',
  payload: {username: 'yangmillstheory'},
})
expect(logout()).to.deep.equal({type: 'LOGOUT'})

License

MIT © 2016, Victor Alvarez

Install

npm i redux-scoped-actions

DownloadsWeekly Downloads

11

Version

0.0.0

License

MIT

Last publish

Collaborators

  • avatar