Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
/*! autodux v1.0.6 by undefined */ | ||
/*! autodux v2.0.1 by Eric Elliott */ | ||
'use strict'; | ||
@@ -7,6 +7,6 @@ | ||
var sliceSelector = curry(function (slice, fn, state) { | ||
return fn(state[slice]); | ||
return fn(state[slice], state); | ||
}); | ||
var autodux = function autodux() { | ||
var autodux = function () { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
@@ -22,16 +22,2 @@ _ref$initial = _ref.initial, | ||
var reducer = function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initial; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
type = _ref2.type, | ||
payload = _ref2.payload; | ||
var _ref3 = type ? type.split('/') : 'unknown/unknown'.split('/'), | ||
namespace = _ref3[0], | ||
subType = _ref3[1]; | ||
return namespace === slice && actions[subType] ? actions[subType].reducer(state, payload) : state; | ||
}; | ||
var createSelector = sliceSelector(slice); | ||
@@ -45,17 +31,31 @@ | ||
var mappedActions = Object.keys(actions).reduce(function (obj, key) { | ||
var mappedActions = Object.keys(actions).reduce(function (obj, action) { | ||
var _Object$assign3; | ||
return Object.assign({}, obj, (_Object$assign3 = {}, _Object$assign3[key] = Object.assign(function () { | ||
var _actions$key; | ||
return Object.assign({}, obj, (_Object$assign3 = {}, _Object$assign3[action] = Object.assign(function () { | ||
var _actions$action; | ||
return { | ||
type: slice + '/' + key, | ||
payload: typeof actions[key].create === 'function' ? (_actions$key = actions[key]).create.apply(_actions$key, arguments) : undefined | ||
type: slice + '/' + action, | ||
payload: typeof actions[action].create === 'function' ? (_actions$action = actions[action]).create.apply(_actions$action, arguments) : arguments.length <= 0 ? undefined : arguments[0] | ||
}; | ||
}, { type: slice + '/' + key }), _Object$assign3)); | ||
}, { type: slice + '/' + action }), _Object$assign3)); | ||
}, {}); | ||
return { | ||
initial: initial, actions: mappedActions, selectors: slicedSelectors, reducer: reducer, slice: slice | ||
initial: initial, actions: mappedActions, selectors: slicedSelectors, reducer: function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initial; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
type = _ref2.type, | ||
payload = _ref2.payload; | ||
var _ref3 = type ? type.split('/') : 'unknown/unknown'.split('/'), | ||
namespace = _ref3[0], | ||
subType = _ref3[1]; | ||
var actionReducer = !actions[subType] ? undefined : typeof actions[subType].reducer == 'function' ? actions[subType].reducer : typeof actions[subType] === 'function' ? actions[subType] : undefined; | ||
return namespace === slice && actions[subType] ? actionReducer ? actionReducer(state, payload) : Object.assign({}, state, payload) : state; | ||
}, slice: slice | ||
}; | ||
@@ -65,2 +65,13 @@ }; | ||
module.exports = autodux; | ||
module.exports.id = function (x) { | ||
return x; | ||
}; | ||
module.exports.assign = function (key) { | ||
return function (state, payload) { | ||
var _Object$assign4; | ||
return Object.assign({}, state, (_Object$assign4 = {}, _Object$assign4[key] = payload, _Object$assign4)); | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "autodux", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Automate the Redux boilerplate.", | ||
"browser": "dist/index.browser.js", | ||
"browser": "dist/index.js", | ||
"main": "dist/index.js", | ||
"module": "dist/index.commonjs.js", | ||
"module": "dist/index-esm.js", | ||
"scripts": { | ||
"lint": "eslint source && echo 'lint finished.'", | ||
"test": "node source/test.js", | ||
"watch": "watch 'clear && npm run -s test && npm run -s lint' source", | ||
"prepare": "prepublish --entry-node source/index.js --entry-web source/index.js" | ||
"lint": "eslint src && echo 'lint finished.'", | ||
"test": "node src/test.js", | ||
"watch": "watch 'clear && npm run -s test && npm run -s lint' src", | ||
"prepare": "npm run test -s && prepublish" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -7,3 +7,3 @@ # Autodux | ||
This library is ready for production testing. Please check it out and file any issues you encounter. | ||
This library is being production tested in several large apps. | ||
@@ -154,3 +154,3 @@ ## Install | ||
With autoDux, if your action creator maps directly from input to payload, you can omit it. autoDux will do it for you. | ||
With autodux, if your action creator maps directly from input to payload, you can omit it. autodux will do it for you. | ||
@@ -178,3 +178,3 @@ By omitting the action creator, you can shorten this: | ||
You don't need to worry about setting the type in autoDux action creators. That's handled for you automatically. In other words, all an action creator has to do is return the payload. | ||
You don't need to worry about setting the type in autodux action creators. That's handled for you automatically. In other words, all an action creator has to do is return the payload. | ||
@@ -190,3 +190,3 @@ With Redux alone you might write: | ||
With autoDux, that becomes: | ||
With autodux, that becomes: | ||
@@ -278,3 +278,3 @@ ```js | ||
}, | ||
//other stuff | ||
// other stuff | ||
``` | ||
@@ -297,2 +297,31 @@ | ||
Although you should avoid selecting state from outside the slice you care about, the root state object is passed as a convenience second argument to selectors: | ||
``` | ||
import autodux from 'autodux'; | ||
const counter = autodux({ | ||
// stuff here | ||
selectors: { | ||
// other selectors | ||
rootState: (_, root) => root | ||
}, | ||
// other stuff | ||
``` | ||
In your unit tests, this allows you to retrieve the entire root state: | ||
```js | ||
test('counter.rootState', assert => { | ||
const msg = 'should return the root state'; | ||
const { rootState } = counter.selectors; | ||
const actual = rootState({ counter: 3, otherSlice: 'data' }); | ||
const expected = { counter: 3, otherSlice: 'data' }; | ||
assert.same(actual, expected, msg); | ||
assert.end(); | ||
}); | ||
``` | ||
## Extras | ||
@@ -299,0 +328,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
33988
461
365
1