-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa31a01
Showing
11 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"stage": 0, | ||
"loose": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lib | ||
**/node_modules | ||
**/webpack.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "standard", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"browser": true, | ||
"mocha": true, | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
*.log | ||
.DS_Store | ||
lib | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
*.log | ||
src | ||
test | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "4.0.0" | ||
script: | ||
- npm run lint | ||
- npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Daniel Bugl | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# redux-recycle | ||
|
||
_higher-order reducer to reset the redux state on certain actions_ | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
npm install --save redux-recycle | ||
``` | ||
|
||
|
||
## API | ||
|
||
```js | ||
recycleState(reducer, [ARRAY_OF_ACTIONS], initialState) | ||
``` | ||
|
||
|
||
## Ignoring actions | ||
|
||
`redux-recycle` is a reducer enhancer (higher-order reducer), it provides the | ||
`recycleState` function, which takes an existing reducer and an array of | ||
actions that will reset the state. Optionally, you can also pass an initial | ||
state to reset to. (defaults to calling your reducer with | ||
`@@redux-recycle/INIT` and an `undefined` state, which will have the same effect | ||
as the initial redux action) | ||
|
||
Firstly, import `redux-recycle`: | ||
|
||
```js | ||
// Redux utility functions | ||
import { combineReducers } from 'redux'; | ||
// Redux Undo store enhancer | ||
import recycleState from 'redux-recycle'; | ||
``` | ||
|
||
Then, add `recycleState` to your reducer(s) like this: | ||
|
||
```js | ||
combineReducers({ | ||
counter: recycleState(counter, [INCREMENT_COUNTER], 0) | ||
}) | ||
``` | ||
|
||
Now, once you click the increment button, the state will be reset to `0`. | ||
|
||
|
||
## What is this magic? How does it work? | ||
|
||
Have a read of the [Implementing Undo History recipe](https://rackt.github.io/redux/docs/recipes/ImplementingUndoHistory.html) | ||
in the Redux documents, which explains in detail how higher-order reducers work. | ||
|
||
|
||
## License | ||
|
||
MIT, see `LICENSE.md` for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "redux-recycle", | ||
"version": "1.0.0", | ||
"description": "higher-order reducer to reset the redux state on certain actions", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"build": "babel src --out-dir lib", | ||
"lint": "eslint src test", | ||
"test": "NODE_ENV=test mocha --compilers js:babel/register --recursive", | ||
"test:watch": "NODE_ENV=test mocha --compilers js:babel/register --recursive --watch", | ||
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive", | ||
"prepublish": "npm run lint && npm run test && npm run clean && npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/omnidan/redux-recycle.git" | ||
}, | ||
"keywords": [ | ||
"redux", | ||
"undo", | ||
"redo", | ||
"flux", | ||
"time travel" | ||
], | ||
"author": "Daniel Bugl <me@omnidan.net> (https://github.com/omnidan)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/omnidan/redux-recycle/issues" | ||
}, | ||
"homepage": "https://github.com/omnidan/redux-recycle", | ||
"devDependencies": { | ||
"babel": "^5.8.23", | ||
"babel-core": "^5.8.25", | ||
"babel-eslint": "^4.1.3", | ||
"babel-loader": "^5.3.2", | ||
"eslint": "^1.7", | ||
"eslint-config-standard": "^4.4.0", | ||
"eslint-plugin-react": "^3.6.0", | ||
"eslint-plugin-standard": "^1.3.1", | ||
"expect": "^1.12.2", | ||
"isparta": "^3.1.0", | ||
"mocha": "^2.3.3", | ||
"rimraf": "^2.4.3" | ||
}, | ||
"dependencies": { | ||
"redux": "^3.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// redux-recycle higher order reducer | ||
export default function recycleState (reducer, actions = [], initialState) { | ||
return (state, action) => { | ||
if (actions.indexOf(action.type) >= 0) { | ||
if (initialState === undefined) { | ||
return reducer(undefined, '@@redux-recycle/INIT') | ||
} | ||
return initialState | ||
} | ||
return reducer(state, action) | ||
} | ||
} | ||
// /redux-recycle |
Empty file.