boilersuit
Advanced tools
Comparing version 0.2.14 to 0.3.0
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
program.version('0.2.14'); | ||
program.version('0.3.0'); | ||
@@ -12,0 +12,0 @@ program |
{ | ||
"name": "boilersuit", | ||
"description": "A CLI tool for generating selectors, reducers, actions, constants and sagas in react-boilerplate", | ||
"version": "0.2.14", | ||
"version": "0.3.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": "matt <matt.pocock@thevirtualforge.com>", |
198
readme.md
@@ -94,8 +94,22 @@ <div style="text-align: center"><img src="https://raw.githubusercontent.com/mattpocock/boilersuit/master/logo.png" height="240px" alt="boilerplate logo"/></div> | ||
The exceptions are the `// @suit-name-only` tags, in which boilersuit only controls the names of functions and properties. | ||
```javascript | ||
// @suit-start | ||
const codeBetweenTheseTags = 'Is entirely controlled by boilersuit.'; | ||
const codeBetweenTheseTags = 'Is deleted and re-written each time suit runs.'; | ||
// @suit-end | ||
const codeBeforeThisTag = 'Is entirely controlled by boilersuit.'; // @suit-line | ||
const codeBeforeThisTag = 'Is deleted and re-written each time suit runs.'; // @suit-line | ||
// @suit-name-only-start | ||
const codeBetweenNameOnlyTags = [ | ||
'Will not be deleted and re-written between runs. Suit will run', | ||
'a find-and-replace with function or action names that have changed,', | ||
'but will keep all code you write inside these tags.', | ||
'', | ||
'Suit will never wholesale delete code between these tags, so you may', | ||
'need to do some manual deletion if suit cannot work out what to alter.', | ||
'But this means you can feel free to edit any code between these tags.', | ||
]; | ||
// @suit-name-only-end | ||
``` | ||
@@ -111,2 +125,6 @@ | ||
#### --force | ||
Add the `--force` modifier if you want suit to re-render everything within a directory. | ||
### Ajax | ||
@@ -122,2 +140,39 @@ | ||
### Reducers | ||
Each `suit.json` file can have multiple reducers, which contain pieces of different state. | ||
These are defined as keys on the main json object. For example, if you needed three API calls to get some config, some posts and some images: | ||
```json | ||
{ | ||
"getConfig": { | ||
"initialState": { | ||
... | ||
}, | ||
"actions": { | ||
... | ||
} | ||
}, | ||
"getPosts": { | ||
"initialState": { | ||
... | ||
}, | ||
"actions": { | ||
... | ||
} | ||
}, | ||
"getImages": { | ||
"initialState": { | ||
... | ||
}, | ||
"actions": { | ||
... | ||
} | ||
} | ||
} | ||
``` | ||
This will create three reducers: `getConfig`, `getPosts`, and `getImages`, and add them to `combineReducers` in the reducers file. | ||
### initialState | ||
@@ -127,10 +182,17 @@ | ||
Suit will create a selector for each of these fields on the initialState, and put them in `mapStateToProps` in your index file. | ||
```json | ||
{ | ||
"initialState": { | ||
"isLoading": false, | ||
"hasSucceeded": true, | ||
"data": null, | ||
"errorMessage": "", | ||
"hasError": false | ||
"getImages": { | ||
"initialState": { | ||
"isLoading": false, | ||
"hasSucceeded": true, | ||
"data": null, | ||
"errorMessage": "", | ||
"hasError": false | ||
}, | ||
"actions": { | ||
... | ||
} | ||
} | ||
@@ -142,13 +204,26 @@ } | ||
#### set | ||
Every reducer has an `"actions": {}` attribute, which is required to make the reducer work. | ||
`type: object` | ||
A reducer can have as many actions as you like. Each action you add will get added to the `actions.js` file, get added to the reducer, get passed to `mapDispatchToProps`, and get a unique entry in the `constants.js` file to make sure it works. | ||
Defines how you want the data to be changed after the action is run. | ||
#### Passing Payloads | ||
Often, actions need to carry payloads - pieces of data that affect the state. Suit allows you to add payloads to your actions. | ||
Let's imagine that we have a popup, with an `isVisible` property. This `isVisible` property gets passed down to our container component in `mapStateToProps`. | ||
But having an `isVisible` property that never changes is pretty useless - we need to be able to change it. | ||
```json | ||
{ | ||
"actions": { | ||
"getFieldsStarted": { | ||
"set": { "isLoading": true } | ||
"popup": { | ||
"initialState": { | ||
"isVisible": false | ||
}, | ||
"actions": { | ||
"changeIsVisible": { | ||
"set": { | ||
"isVisible": "payload" | ||
} | ||
} | ||
} | ||
@@ -159,14 +234,42 @@ } | ||
#### payload | ||
`"payload"` is treated as special by suit. It means that when you pass a payload to this action, it will get sent to the state. | ||
`type: bool` | ||
If you want to pass an object as a payload, for instance to set the color of the popup as well as the visibility: | ||
Whether or not you want the action to carry a payload. | ||
```json | ||
{ | ||
"popup": { | ||
"initialState": { | ||
"isVisible": false, | ||
"color": "#fff" | ||
}, | ||
"actions": { | ||
"changePopup": { | ||
"set": { | ||
"isVisible": "payload.isVisible", | ||
"color": "payload.color" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
Then you can call `submitChangePopUp({ isVisible: true, color: 'red' })`, and it'll work. | ||
#### Payloads and Sagas | ||
Sometimes, you'll need to pass a payload in an action that won't affect the state. For instance, when you need to pass a payload to a saga. For this case, use `"payload": true` on the action: | ||
```json | ||
{ | ||
"actions": { | ||
"getFieldsStarted": { | ||
"payload": true, | ||
"set": { "isLoading": true } | ||
"getImages": { | ||
"initialState": { | ||
... | ||
}, | ||
"actions": { | ||
"getImagesStarted": { | ||
"payload": true, | ||
"set": { "isLoading": true } | ||
} | ||
} | ||
@@ -177,2 +280,23 @@ } | ||
#### set | ||
`type: object` | ||
Defines how you want the data to be changed after the action is run. | ||
```json | ||
{ | ||
"getImages": { | ||
"initialState": { | ||
... | ||
}, | ||
"actions": { | ||
"getImagesStarted": { | ||
"set": { "isLoading": true } | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
#### passAsProp | ||
@@ -182,4 +306,6 @@ | ||
Whether or not you want to pass this action to the container component as a dispatch. | ||
Whether or not you want to pass this action to the container component in `mapDispatchToProps`. | ||
If passAsProp is not specified on any of your actions, boilersuit will pass **all your actions** to the index file. But adding `"passAsProp": true` to any of your actions will mean only that one gets put in `mapDispatchToProps`. | ||
```json | ||
@@ -198,14 +324,24 @@ { | ||
`type: bool` | ||
Sagas handle asynchronous calls in redux. In boilersuit, we support a very simple type of saga - one with a fail case and a success case. | ||
Whether or not you want to generate a saga that is fired from this action. | ||
You pass this as an object, as in the example below: | ||
Sagas are interesting in boilersuit - because they are so complex, and can be used in so many divergent ways, we don't control them in the same way that we do with other files. Specifying `"saga": true` on an action will generate some boilerplate in the sagas file which you will then have to customise and manage. | ||
```json | ||
{ | ||
"actions": { | ||
"getFieldsStarted": { | ||
"saga": true, | ||
"set": { "isLoading": true } | ||
"initialState": { | ||
... | ||
}, | ||
"getImagesStarted": { | ||
"saga": { | ||
"onFail": "getImagesFailed", | ||
"onSuccess": "getImagesSucceeded" | ||
}, | ||
"set": { ... } | ||
}, | ||
"getImagesFailed": { | ||
"set": { ... } | ||
}, | ||
"getImagesSucceeded": { | ||
"set": { ... } | ||
} | ||
@@ -216,2 +352,4 @@ } | ||
Also, you can only have one action that creates a saga file per reducer. | ||
#### describe | ||
@@ -255,4 +393,4 @@ | ||
{ | ||
"stopDescribeWarnings": true | ||
"showDescribeWarnings": true | ||
} | ||
``` |
@@ -12,4 +12,4 @@ const { concat } = require('./utils'); | ||
if ( | ||
typeof config.stopDescribeWarning === 'undefined' || | ||
!config.stopDescribeWarning | ||
typeof config.showDescribeWarnings !== 'undefined' || | ||
config.showDescribeWarnings | ||
) { | ||
@@ -16,0 +16,0 @@ if (!domain.describe) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
436209
386