-
Notifications
You must be signed in to change notification settings - Fork 0
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 d297c6a
Showing
10 changed files
with
4,238 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,5 @@ | ||
{ | ||
"presets": [ | ||
"env" | ||
] | ||
} |
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,2 @@ | ||
node_modules/ | ||
coverage/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
{ | ||
"name": "combine-reducers", | ||
"version": "1.0.0", | ||
"main": "src/combine-reducers.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "webpack" | ||
}, | ||
"devDependencies": { | ||
"babel": "^6.23.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-preset-env": "^1.6.1", | ||
"jest": "^22.1.4", | ||
"uglifyjs-webpack-plugin": "^1.1.6", | ||
"webpack": "^3.10.0" | ||
} | ||
} |
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,24 @@ | ||
# combine-reducers | ||
|
||
a standalone ES6 combine-reducers function. Unit tested. Babel pre-configured. | ||
|
||
``` | ||
yarn run v1.3.2 | ||
$ jest --coverage | ||
PASS test/combine-reducers.test.js | ||
combineReducers | ||
✓ should add a customer and a pony into eachs state (3ms) | ||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: 0.895s, estimated 1s | ||
Ran all test suites. | ||
---------------------|----------|----------|----------|----------|----------------| | ||
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | | ||
---------------------|----------|----------|----------|----------|----------------| | ||
All files | 100 | 0 | 100 | 100 | | | ||
combine-reducers.js | 100 | 0 | 100 | 100 | 1 | | ||
---------------------|----------|----------|----------|----------|----------------| | ||
✨ Done in 1.88s. | ||
``` |
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,8 @@ | ||
export default (reducers = {}) => (state = {}, action) => | ||
Object.assign( | ||
{}, | ||
state, | ||
...Object.keys(reducers).map(key => ({ | ||
[key]: reducers[key](state[key], action) | ||
}) | ||
)) |
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,26 @@ | ||
import combineReducers from '../src/combine-reducers' | ||
|
||
const reducerCustomers = (state = [], action) => action.type === 'SET_CUSTOMER' ? { | ||
customer: action.customer | ||
} : state | ||
const reducerPonys = (state = [], action) => action.type === 'SET_PONY' ? { | ||
pony: action.pony | ||
} : state | ||
|
||
describe('combineReducers', () => { | ||
it('should add a customer and a pony into eachs state', () =>{ | ||
const customer = {name: `customer-${Math.random(100)}`} | ||
const pony = {name: `pony-${Math.random(100)}`} | ||
|
||
const combinedReducers = combineReducers({ | ||
reducerCustomers, | ||
reducerPonys | ||
}); | ||
|
||
const firstState = combinedReducers({}, { type: 'SET_CUSTOMER', customer }) | ||
expect(firstState.reducerCustomers.customer).toEqual(customer) | ||
|
||
const secondState = combinedReducers(firstState, { type: 'SET_PONY', pony }) | ||
expect(secondState.reducerPonys.pony).toEqual(pony) | ||
}) | ||
}) |
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,28 @@ | ||
const path = require('path'); | ||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
|
||
module.exports = { | ||
entry: './src/combine-reducers.js', | ||
output: { | ||
filename: 'bundle.js', | ||
path: path.resolve(__dirname, 'dist') | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel-loader', | ||
query: { | ||
presets: ['env'] | ||
} | ||
} | ||
] | ||
}, | ||
stats: { | ||
colors: true | ||
}, | ||
devtool: 'source-map', | ||
plugins: [ | ||
new UglifyJsPlugin() | ||
] | ||
}; |
Oops, something went wrong.