https://github.com/ruben-arushanyan/actions-creator
actions-creator is an awesome javascript package that allows you to dynamically create action objects in Redux without having to declare constants and separate action-creator functions for each action.
https://github.com/ruben-arushanyan/actions-creator
actions actions-creator create-action javascript produce-by-path redux redux-action redux-action-callback redux-cool
Last synced: about 1 year ago
JSON representation
actions-creator is an awesome javascript package that allows you to dynamically create action objects in Redux without having to declare constants and separate action-creator functions for each action.
- Host: GitHub
- URL: https://github.com/ruben-arushanyan/actions-creator
- Owner: Ruben-Arushanyan
- License: mit
- Created: 2021-04-10T14:21:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T08:03:37.000Z (over 3 years ago)
- Last Synced: 2024-05-01T19:41:48.826Z (about 2 years ago)
- Topics: actions, actions-creator, create-action, javascript, produce-by-path, redux, redux-action, redux-action-callback, redux-cool
- Language: JavaScript
- Homepage: https://actions-creator.js.org
- Size: 1.31 MB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# [Actions Creator - Redux](https://actions-creator.js.org)
> You can find the full documentation on the [website](https://actions-creator.js.org)
## Description
**actions-creator** is an awesome javascript package that allows you to **dynamically** create action objects in Redux **without** declaring *CONSTANTS* and separate *action-creator* functions for each action.
## [Documentation](https://actions-creator.js.org)
- [Actions Creator](https://actions-creator.js.org/docs/actions-creator)
- [Customization](https://actions-creator.js.org/docs/customization)
## Installation
```bash
npm install actions-creator
```
## Usage Example
```javascript
import {actionsCreator} from 'actions-creator'
const action_1 = actionsCreator.MY.FIRST.ACTION('arg1')
// {
// type: 'MY/FIRST/ACTION',
// payload: 'arg1',
// }
const action_2 = actionsCreator.This.is.my.second.action(2021)
// {
// type: 'This/is/my/second/action',
// payload: 2021,
// }
// To get the type of action
String( actionsCreator.MY.FIRST.ACTION ) // 'MY/FIRST/ACTION'
// or
actionsCreator.MY.FIRST.ACTION().type // 'MY/FIRST/ACTION'
```
## Actions With Callback
Sometimes we need the action to have **callback capability**. It might be necessary in many cases.
**`Actions Creator`** allows us to do this in a beautiful way:
When we try to generate an action object, we can pass the **callback function** as the last argument. `Actions Creator` will check and if the last argument is a function, it will be considered as a **callback function**.
```javascript
import {actionsCreator} from 'actions-creator'
const callback = () => {
console.log('Hello, I am callback!!!')
}
const action = actionsCreator.MY.CALLBACKABLE.ACTION(123, callback)
// {
// type: 'MY/CALLBACKABLE/ACTION',
// payload: 123,
// cb: [Function callback],
// }
action.cb() // 'Hello, I am callback!!!'
```
## Syntax
### `actionsCreator.ANY.ACTION(payload, callback?)`
- **payload** ``
Any value as a payload.
- **callback** ``
Any function as a callback.
**Returns** ``
- **type** `` Action type as a string.
```js
actionsCreator.ANY.ACTION().type === 'ANY/ACTION' // true
```
- **payload** ``
The value of the payload - given in the first argument.
```js
actionsCreator.ANY.ACTION(123).payload === 123 // true
```
- **cb** ``
The function of the callback - given in the last argument.
```js
const callback = () => {};
actionsCreator.ANY.ACTION(123, callback).cb === callback // true
```
## Customize
We do not recommend to customize,
but if you need to do it, you can easily do that: \
see: [Produce By Path Pattern](https://github.com/ruben-arushanyan/produce-by-path)
## [Contributing](https://github.com/ruben-arushanyan/actions-creator/blob/master/CONTRIBUTING.md)
Read our [contributing guide](https://github.com/ruben-arushanyan/actions-creator/blob/master/CONTRIBUTING.md) to learn about our development process.
## [Code of Conduct](https://github.com/ruben-arushanyan/actions-creator/blob/master/CODE_OF_CONDUCT.md)
This project has adopted the [Contributor Covenant](https://www.contributor-covenant.org) as its Code of Conduct, and we expect project participants to adhere to it. Please read the [full text](https://github.com/ruben-arushanyan/actions-creator/blob/master/CODE_OF_CONDUCT.md) so that you can understand what actions will and will not be tolerated.
## Authors
- [Ruben Arushanyan](https://github.com/ruben-arushanyan)
## License
[MIT License](https://github.com/ruben-arushanyan/actions-creator/blob/master/LICENSE)