create-actions
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -18,9 +18,8 @@ "use strict"; | ||
var id = namespace + "/" + name; | ||
actions[name] = { | ||
id: id, | ||
dispatch: obj[name], | ||
fsa: function fsa(x) { | ||
return { type: id, payload: obj[name](x) }; | ||
} | ||
var action = function action(x) { | ||
return { type: id, payload: obj[name](x) }; | ||
}; | ||
action.id = id; | ||
action.dispatch = obj[name]; | ||
actions[name] = action; | ||
return actions; | ||
@@ -27,0 +26,0 @@ }, {}); |
{ | ||
"name": "create-actions", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "FSA compliant way of creating actions automatically", | ||
@@ -5,0 +5,0 @@ "main": "lib/createActions.js", |
# create-actions | ||
> | ||
> A tool to create action creators | ||
Why would you use this? | ||
If you're working with instances of alt or if you want to use action creators then this facilitates the creation of them by keeping your code concise. | ||
Alt [supports](https://github.com/goatslacker/alt/commit/cd54ed13040ceb6edf1826ec5cbc69facdf9a19e) using action creators to dispatch, this means you can `import` your actions directly in a component to use them rather than inject it through using context. | ||
Example action creator | ||
```js | ||
const CountIncremented = { | ||
id: 'increment', | ||
dispatch() { | ||
return 1 | ||
} | ||
} | ||
``` | ||
You can then listen to this action in your store normally | ||
```js | ||
this.bindAction(CountIncremented, this.incrementCount) | ||
``` | ||
and you can dispatch it using `alt.dispatch` | ||
```js | ||
alt.dispatch(CountIncremented) | ||
``` | ||
Writing various actions can be tedious so this tool creates a shorthand for creating them. | ||
Use it to create your own actions. Actions return the data they want to dispatch. | ||
@@ -33,1 +64,10 @@ Good for use with [Alt](https://github.com/goatslacker/alt) | ||
``` | ||
Using this with something like [`redux`](https://github.com/rackt/redux) is also straightforward. | ||
```js | ||
import { generateActions } from 'create-actions' | ||
const DocumentActions = generateActions('DocumentActions', ['changedTitle']) | ||
store.dispatch(DocumentActions.changedTitle.dispatch('This is the new title')) | ||
``` |
4566
73
54