providence
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -41,2 +41,4 @@ /** | ||
var DELETEIN_PATH = ['deleteIn']; | ||
var FOREACH_PATH = ['forEach']; | ||
var REDUCE_PATH = ['reduce']; | ||
var ONUPDATE_PATH = ['onUpdate']; | ||
@@ -50,3 +52,3 @@ // Internal _onUpdate function; useful for when Providence is inherited. | ||
// to be used to set on the key path in the case that there is no value set in the key path. | ||
var DEFAULTS = [[UNBOXER_PATH, IDENTITY], [BOXER_PATH, IDENTITY], [PATH_PATH, INITIAL_PATH], [GETIN_PATH, _defaultGetIn], [SETIN_PATH, _defaultSetIn], [DELETEIN_PATH, _defaultDeleteIn]]; | ||
var DEFAULTS = [[UNBOXER_PATH, IDENTITY], [BOXER_PATH, IDENTITY], [PATH_PATH, INITIAL_PATH], [GETIN_PATH, _default.bind(null, 'getIn')], [SETIN_PATH, _default.bind(null, 'setIn')], [DELETEIN_PATH, _default.bind(null, 'deleteIn')], [FOREACH_PATH, _default.bind(null, 'forEach')], [REDUCE_PATH, _default.bind(null, 'reduce')]]; | ||
var PATH = 0; | ||
@@ -344,2 +346,56 @@ var VALUE = 1; | ||
Providence.prototype.forEach = function (sideEffect) { | ||
var _this = this; | ||
for (var _len = arguments.length, rest = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
rest[_key - 1] = arguments[_key]; | ||
} | ||
var state = this.deref(NOT_SET); | ||
if (state === NOT_SET) { | ||
return; | ||
} | ||
var fetchForEach = this._options.getIn(FOREACH_PATH); | ||
var forEach = fetchForEach(state); | ||
var wrapped = function wrapped(value, key) { | ||
for (var _len2 = arguments.length, _rest = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
_rest[_key2 - 2] = arguments[_key2]; | ||
} | ||
var cursor = _this.cursor(key); | ||
return sideEffect.call.apply(sideEffect, [sideEffect, cursor, key].concat(_rest)); | ||
}; | ||
return forEach.apply(undefined, [wrapped].concat(rest)); | ||
}; | ||
Providence.prototype.reduce = function (reducer) { | ||
var _this2 = this; | ||
for (var _len3 = arguments.length, rest = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
rest[_key3 - 1] = arguments[_key3]; | ||
} | ||
var state = this.deref(NOT_SET); | ||
if (state === NOT_SET) { | ||
return; | ||
} | ||
var fetchReduce = this._options.getIn(REDUCE_PATH); | ||
var reduce = fetchReduce(state); | ||
var wrapped = function wrapped(accumulator, value, key) { | ||
for (var _len4 = arguments.length, _rest = Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) { | ||
_rest[_key4 - 3] = arguments[_key4]; | ||
} | ||
var cursor = _this2.cursor(key); | ||
return reducer.call.apply(reducer, [reducer, accumulator, cursor, key].concat(_rest)); | ||
}; | ||
return reduce.apply(undefined, [wrapped].concat(rest)); | ||
}; | ||
Providence.prototype.unboxRootData = function () { | ||
@@ -487,12 +543,4 @@ var options = this._options; | ||
function _defaultGetIn(rootData) { | ||
return rootData.getIn.bind(rootData); | ||
} | ||
function _defaultSetIn(rootData) { | ||
return rootData.setIn.bind(rootData); | ||
} | ||
function _defaultDeleteIn(rootData) { | ||
return rootData.deleteIn.bind(rootData); | ||
function _default(method, rootData) { | ||
return rootData[method].bind(rootData); | ||
} |
{ | ||
"name": "providence", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "Reference a sub-structure of any data structure", | ||
@@ -33,3 +33,3 @@ "main": "modules/index.js", | ||
"devDependencies": { | ||
"babel": "^5.4.4", | ||
"babel": "^5.4.7", | ||
"chai": "^2.3.0", | ||
@@ -40,6 +40,6 @@ "mocha": "^2.2.5" | ||
"lodash.get": "^3.7.0", | ||
"lodash.has": "^3.2.0", | ||
"lodash.has": "^3.2.1", | ||
"lodash.isplainobject": "^3.1.0", | ||
"lodash.set": "^3.7.2" | ||
"lodash.set": "^3.7.4" | ||
} | ||
} |
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
24932
451
Updatedlodash.has@^3.2.1
Updatedlodash.set@^3.7.4