0.7.1 • Published 7 years ago

action-creator v0.7.1

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

action-creator

A simple way to write function with context dependencies without context parameter


中文

Get started

install

npm install action-creator
# or
yarn add action-creator

usage

import {bindActionCreators, connect} from 'action-creator'

Docs

1. bindActionCreators(object: actionCreators)(ctx) => object: actions

Param actionCreators is a object contain action creators, like:

bindActionCreators({
  getIp: () => {},
  getUserName: () => {},
})

it will return a function, and then pass param ctx to this function. like:

const ctx = {
  req: {},
  res: {}
}

bindActionCreators({
  getIp: () => {},
  getUserName: () => {},
})(ctx)

it will return a object contains {getIp, getUserName}, now you can use getIp directly.

2. connect(function: bindActionCreators(actionCreators))(beConnected) => function: wrappedActionCreator

An action is written like (..args) => (ctx, getAction) => {...}, so if you want to use getAction method, you must connect it with other actions you need. like:

const getName = (...args) => (ctx, getAction) => {
  const {getParentName} = getAction()
  return getParentName(...args) + args[1]
}
// ... after do bindActionCreators(...)(ctx), you run getName() will
// cause an Error 'getParentName is not a function'

const connectedGetName = connect(
  bindActionCreators({
    getParentName
  })
)(getName)
// this will be ok

License

MIT

0.7.1

7 years ago

0.7.0

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.3-beta.10

7 years ago

0.6.3-beta.9

7 years ago

0.6.3-beta.8

7 years ago

0.6.3-beta.7

7 years ago

0.6.3-beta.6

7 years ago

0.6.3-beta.5

7 years ago

0.6.3-beta.4

7 years ago

0.6.3-beta.3

7 years ago

0.6.3-beta.2

7 years ago

0.6.3-beta.1

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.3.0-beta3

7 years ago

0.3.0-beta2

7 years ago

0.3.0-beta1

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago