Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

action-creator

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

action-creator

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

  • 0.7.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 13 Sep 2017

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