Skip to content

Commit bca1c09

Browse files
authored
Merge pull request #1 from reactor-studio/develop
Merge develop into master
2 parents 9325743 + a24be9f commit bca1c09

20 files changed

+1704
-442
lines changed

.all-contributorsrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"projectName": "re-create-actions",
3+
"projectOwner": "reactor-studio",
4+
"files": [
5+
"README.md"
6+
],
7+
"imageSize": 100,
8+
"commit": true,
9+
"contributors": [
10+
{
11+
"login": "wedranb",
12+
"name": "Vedran Blazenka",
13+
"avatar_url": "https://avatars3.githubusercontent.com/u/1723170?v=4",
14+
"profile": "https://www.vblazenka.com/",
15+
"contributions": [
16+
"code",
17+
"doc"
18+
]
19+
},
20+
{
21+
"login": "dinodsaurus",
22+
"name": "Dino Trojak",
23+
"avatar_url": "https://avatars2.githubusercontent.com/u/1530952?v=4",
24+
"profile": "http://reactor.studio",
25+
"contributions": [
26+
"code"
27+
]
28+
}
29+
]
30+
}

.babelrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
["env", {
5+
"modules": false
6+
}]
7+
],
8+
"env": {
9+
"production": {
10+
"plugins": [
11+
"external-helpers",
12+
"transform-object-rest-spread"
13+
]
14+
},
15+
"test":{
16+
"plugins": [
17+
"transform-runtime",
18+
"external-helpers",
19+
"transform-object-rest-spread"
20+
]
21+
}
22+
}
23+
}

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
root = true
3+
4+
[*]
5+
6+
# Change these settings to your own preference
7+
indent_style = space
8+
indent_size = 2
9+
10+
# We recommend you to keep these unchanged
11+
end_of_line = lf
12+
charset = utf-8
13+
trim_trailing_whitespace = true
14+
insert_final_newline = true
15+
16+
[*.md]
17+
trim_trailing_whitespace = false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "7"
4+
- "8"

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Introduction
2+
[![Build Status](https://travis-ci.org/reactor-studio/re-create-actions.svg?branch=master)](https://travis-ci.org/reactor-studio/re-create-actions)
3+
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
4+
5+
6+
Reduce boilerplate of your Redux actions by creating [flux-standard-actions](https://github.com/acdlite/flux-standard-action) with a set of utilities this package provides.
7+
8+
## TL;DR
9+
10+
```javascript
11+
// actions.js
12+
import {
13+
createAction,
14+
createRequestTypes,
15+
createRequestActions
16+
} from 're-create-actions';
17+
18+
// Constans
19+
const GET_GITHUB_USERS = 'GET_GITHUB_USERS';
20+
21+
// Create action creator
22+
export const getGithubUsers = createAction(GET_GITHUB_USERS);
23+
// Use: dispatch(getGithubUsers())
24+
25+
// Create network types/constants
26+
const GET_GITHUB_USERS_RT = createRequestTypes('GET_GITHUB_USERS_RT');
27+
// Use: GET_GITHUB_USERS_RT.REQUESTED, GET_GITHUB_USERS_RT.COMPLETED, GET_GITHUB_USERS_RT.FAILED
28+
29+
// Create actions from network types
30+
const getGithubUsersRT = createRequestActions(GET_GITHUB_USERS_RT);
31+
// Use: dispatch(getGithubUsersRT.requested())
32+
33+
```
34+
35+
# Install
36+
37+
### NPM
38+
```bash
39+
$ npm install re-create-actions --save
40+
```
41+
42+
### Yarn
43+
```bash
44+
$ yarn add re-create-actions
45+
```
46+
47+
# Usage
48+
Every helper will create action that is defined in shape by Flux standard action. We decided to go with Flux standard action because it gives you definition of minimal, common standards that are human-friendly and enable
49+
us to create assumptions about the shape of our actions.
50+
51+
*NOTE*: You can't disable flux standard action structure at the moment. But there is an [open issue]() for this.
52+
53+
# API
54+
55+
## createAction (type, payloadCreator, metaCreator)
56+
57+
#### type (required)
58+
Type: `string`
59+
60+
Type for your type property in [action](https://redux.js.org/basics/actions)
61+
62+
#### payloadCreator (optional)
63+
Type: `function`
64+
65+
Custom payload creator for action payload
66+
67+
#### metaCreator (optional)
68+
Type: `function`
69+
70+
Custom meta creator for action
71+
72+
73+
# createRequestTypes(type)
74+
75+
#### type
76+
Type: `string`
77+
78+
Type for your request types
79+
80+
## Credits
81+
Projects was inspired by headaches given from reading bunch of boilerplates during pull request reveiws at [reactor.studio](https://github.com/reactor-studio`).
82+
83+
API for this package was inspired by this awesome projects:
84+
* [flux-standard-action](https://github.com/acdlite/flux-standard-action)
85+
* [redux-actions](https://github.com/reduxactions/redux-actions)
86+
87+
88+
## Contributors
89+
90+
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
91+
92+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
93+
<!-- prettier-ignore -->
94+
| [<img src="https://avatars3.githubusercontent.com/u/1723170?v=4" width="100px;"/><br /><sub><b>Vedran Blazenka</b></sub>](https://www.vblazenka.com/)<br />[💻](https://github.com/reactor-studio/re-create-actions/commits?author=wedranb "Code") [📖](https://github.com/reactor-studio/re-create-actions/commits?author=wedranb "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1530952?v=4" width="100px;"/><br /><sub><b>Dino Trojak</b></sub>](http://reactor.studio)<br />[💻](https://github.com/reactor-studio/re-create-actions/commits?author=dinodsaurus "Code") |
95+
| :---: | :---: |
96+
<!-- ALL-CONTRIBUTORS-LIST:END -->
97+
98+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

package.json

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,46 @@
22
"name": "re-create-actions",
33
"version": "0.0.1",
44
"description": "Group of utilities for creating Flux standard actions.",
5-
"main": "src/index.js",
5+
"main": "dist/bundle.js",
66
"repository": "https://github.com/reactor-studio/re-create-actions",
77
"author": "Vedran Blazenka <[email protected]>",
88
"license": "MIT",
9+
"ava": {
10+
"require": [
11+
"babel-register"
12+
],
13+
"babel": "inherit"
14+
},
915
"scripts": {
10-
"test": "xo && ava"
16+
"build": "NODE_ENV=production rollup -c",
17+
"test": "NODE_ENV=test xo && ava",
18+
"contributors:add": "all-contributors add",
19+
"contributors:generate": "all-contributors generate"
1120
},
1221
"devDependencies": {
1322
"ava": "^0.25.0",
14-
"xo": "^0.18.2"
23+
"babel-plugin-external-helpers": "^6.22.0",
24+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
25+
"babel-plugin-transform-runtime": "^6.23.0",
26+
"babel-preset-env": "^1.6.1",
27+
"babel-preset-es2015": "^6.24.1",
28+
"babelrc-rollup": "^3.0.0",
29+
"rollup": "^0.56.2",
30+
"rollup-plugin-babel": "^3.0.3",
31+
"rollup-plugin-commonjs": "^8.3.0",
32+
"rollup-plugin-node-resolve": "^3.0.2",
33+
"xo": "^0.20.3"
1534
},
1635
"dependencies": {
17-
"flux-standard-action": "^2.0.1"
36+
"flux-standard-action": "^2.0.1",
37+
"invariant": "^2.2.2",
38+
"lodash": "^4.17.5"
1839
},
1940
"xo": {
2041
"esnext": true,
2142
"space": 2,
22-
"kebab": false
43+
"ignores": [
44+
"rollup.config.js"
45+
]
2346
}
2447
}

rollup.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import babel from 'rollup-plugin-babel';
3+
import babelrc from 'babelrc-rollup';
4+
// import commonjs from 'rollup-plugin-commonjs';
5+
6+
const pkg = require('./package.json');
7+
8+
const external = Object.keys(pkg.dependencies);
9+
10+
const plugins = [
11+
resolve({
12+
jsnext: true,
13+
main: true
14+
}),
15+
babel(babelrc()),
16+
];
17+
18+
export default {
19+
entry: 'src/index.js',
20+
output: {
21+
file: 'dist/index.js',
22+
format: 'cjs'
23+
},
24+
plugins: plugins,
25+
external: external,
26+
}
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
11
import test from 'ava';
2+
3+
import {isFSA} from 'flux-standard-action';
24
import createAction from '../create-action';
3-
import createRequestTypes from '../create-request-types';
4-
import createActionsFromTypes from '../create-actions-from-types';
55

66
// Constants
77
const SIMPLE_ACTION_CONSTANT = 'SIMPLE_ACTION_CONSTANT';
88

99
let simpleAction;
10-
let SIMPLE_NETWORK_CONSTANT_RT;
11-
let simpleActionConstantRT;
1210

1311
// Prepare tests
1412
test.before(() => {
1513
// Create action creator without payload
1614
simpleAction = createAction(SIMPLE_ACTION_CONSTANT);
15+
});
1716

18-
// Create network constants with suffixes
19-
SIMPLE_NETWORK_CONSTANT_RT = createRequestTypes('SIMPLE_NETWORK_CONSTANT_RT');
20-
21-
// Create action creators from network constants
22-
simpleActionConstantRT = createActionsFromTypes(SIMPLE_NETWORK_CONSTANT_RT);
17+
test('createActions returns valid flux standard action', t => {
18+
t.is(isFSA(simpleAction()), true);
2319
});
2420

2521
test('createAction should return action creator with a type', t => {
2622
t.deepEqual(simpleAction(), {
27-
type: SIMPLE_ACTION_CONSTANT
28-
});
29-
});
30-
31-
test('createRequestTypes should return a list of types with request suffixes', t => {
32-
t.deepEqual(SIMPLE_NETWORK_CONSTANT_RT, {
33-
REQUESTED: SIMPLE_NETWORK_CONSTANT_RT.REQUESTED,
34-
COMPLETED: SIMPLE_NETWORK_CONSTANT_RT.COMPLETED,
35-
FAILED: SIMPLE_NETWORK_CONSTANT_RT.FAILED
23+
type: SIMPLE_ACTION_CONSTANT,
24+
error: false
3625
});
3726
});
3827

39-
test('createActionsFromTypes should return a list of action creators with request types', t => {
40-
t.deepEqual(simpleActionConstantRT.requested(), {
41-
type: SIMPLE_NETWORK_CONSTANT_RT.REQUESTED
28+
test('createAction should return action with custom payload', t => {
29+
const customPayloadAction = createAction(SIMPLE_ACTION_CONSTANT, payload => ({
30+
newProp: payload
31+
}));
32+
33+
t.deepEqual(customPayloadAction('lorem ispum'), {
34+
type: SIMPLE_ACTION_CONSTANT,
35+
payload: {
36+
newProp: 'lorem ispum'
37+
},
38+
error: false
4239
});
4340
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import test from 'ava';
2+
import createConfig from '../create-config';
3+
4+
test('should set config and return it', t => {
5+
const config = createConfig({
6+
requestSuffixes: ['R', 'C', 'F']
7+
});
8+
9+
t.deepEqual(config, {
10+
requestSuffixes: ['R', 'C', 'F']
11+
});
12+
});

0 commit comments

Comments
 (0)