final-form-calculate
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -5,12 +5,3 @@ 'use strict'; | ||
// | ||
var toPath = function toPath(key) { | ||
if (key === null || key === undefined) { | ||
return []; | ||
} | ||
if (typeof key !== 'string') { | ||
throw new Error('toPath() expects a string'); | ||
} | ||
return key.length ? key.split(/[.[\]]+/).filter(Boolean) : []; | ||
}; | ||
var finalForm = require('final-form'); | ||
@@ -23,42 +14,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
// | ||
var isPromise = (function (obj) { | ||
return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; | ||
}); | ||
var getIn = function getIn(state, complexKey) { | ||
// Intentionally using iteration rather than recursion | ||
var path = toPath(complexKey); | ||
var current = state; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
if (current === undefined || current === null || (typeof current === 'undefined' ? 'undefined' : _typeof(current)) !== 'object' || Array.isArray(current) && isNaN(key)) { | ||
return undefined; | ||
} | ||
current = current[key]; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return current; | ||
}; | ||
// | ||
var tripleEquals$1 = function tripleEquals(a, b) { | ||
var tripleEquals = function tripleEquals(a, b) { | ||
return a === b; | ||
@@ -78,14 +36,31 @@ }; | ||
var runUpdates = function runUpdates(field, isEqual, updates) { | ||
var next = values && getIn(values, field); | ||
var previous = previousValues && getIn(previousValues, field); | ||
var next = values && finalForm.getIn(values, field); | ||
var previous = previousValues && finalForm.getIn(previousValues, field); | ||
if (!isEqual(next, previous)) { | ||
if (typeof updates === 'function') { | ||
var results = updates(next, field, values); | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
if (isPromise(results)) { | ||
results.then(function (resolved) { | ||
Object.keys(resolved).forEach(function (destField) { | ||
form.change(destField, resolved[destField]); | ||
}); | ||
}); | ||
} else { | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
} | ||
} else { | ||
Object.keys(updates).forEach(function (destField) { | ||
var update = updates[destField]; | ||
form.change(destField, update(next, values)); | ||
var result = update(next, values); | ||
if (isPromise(result)) { | ||
result.then(function (resolved) { | ||
form.change(destField, resolved); | ||
}); | ||
} else { | ||
form.change(destField, result); | ||
} | ||
}); | ||
@@ -102,3 +77,3 @@ } | ||
if (typeof field === 'string') { | ||
runUpdates(field, isEqual || tripleEquals$1, updates); | ||
runUpdates(field, isEqual || tripleEquals, updates); | ||
} else { | ||
@@ -113,3 +88,3 @@ // field is a either array or regex | ||
if (matches(fieldName)) { | ||
runUpdates(fieldName, isEqual || tripleEquals$1, updates); | ||
runUpdates(fieldName, isEqual || tripleEquals, updates); | ||
} | ||
@@ -116,0 +91,0 @@ }); |
@@ -1,11 +0,2 @@ | ||
// | ||
var toPath = function toPath(key) { | ||
if (key === null || key === undefined) { | ||
return []; | ||
} | ||
if (typeof key !== 'string') { | ||
throw new Error('toPath() expects a string'); | ||
} | ||
return key.length ? key.split(/[.[\]]+/).filter(Boolean) : []; | ||
}; | ||
import { getIn } from 'final-form'; | ||
@@ -18,42 +9,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
// | ||
var isPromise = (function (obj) { | ||
return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; | ||
}); | ||
var getIn = function getIn(state, complexKey) { | ||
// Intentionally using iteration rather than recursion | ||
var path = toPath(complexKey); | ||
var current = state; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
if (current === undefined || current === null || (typeof current === 'undefined' ? 'undefined' : _typeof(current)) !== 'object' || Array.isArray(current) && isNaN(key)) { | ||
return undefined; | ||
} | ||
current = current[key]; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return current; | ||
}; | ||
// | ||
var tripleEquals$1 = function tripleEquals(a, b) { | ||
var tripleEquals = function tripleEquals(a, b) { | ||
return a === b; | ||
@@ -78,9 +36,26 @@ }; | ||
var results = updates(next, field, values); | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
if (isPromise(results)) { | ||
results.then(function (resolved) { | ||
Object.keys(resolved).forEach(function (destField) { | ||
form.change(destField, resolved[destField]); | ||
}); | ||
}); | ||
} else { | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
} | ||
} else { | ||
Object.keys(updates).forEach(function (destField) { | ||
var update = updates[destField]; | ||
form.change(destField, update(next, values)); | ||
var result = update(next, values); | ||
if (isPromise(result)) { | ||
result.then(function (resolved) { | ||
form.change(destField, resolved); | ||
}); | ||
} else { | ||
form.change(destField, result); | ||
} | ||
}); | ||
@@ -97,3 +72,3 @@ } | ||
if (typeof field === 'string') { | ||
runUpdates(field, isEqual || tripleEquals$1, updates); | ||
runUpdates(field, isEqual || tripleEquals, updates); | ||
} else { | ||
@@ -108,3 +83,3 @@ // field is a either array or regex | ||
if (matches(fieldName)) { | ||
runUpdates(fieldName, isEqual || tripleEquals$1, updates); | ||
runUpdates(fieldName, isEqual || tripleEquals, updates); | ||
} | ||
@@ -111,0 +86,0 @@ }); |
@@ -9,15 +9,11 @@ (function (global, factory) { | ||
var toPath = function toPath(key) { | ||
if (key === null || key === undefined) { | ||
if (key === null || key === undefined || !key.length) { | ||
return []; | ||
} | ||
if (typeof key !== 'string') { | ||
throw new Error('toPath() expects a string'); | ||
} | ||
return key.length ? key.split(/[.[\]]+/).filter(Boolean) : []; | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
return key.split(/[.[\]]+/).filter(Boolean); | ||
}; | ||
@@ -31,28 +27,11 @@ | ||
var current = state; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
for (var i = 0; i < path.length; i++) { | ||
var key = path[i]; | ||
if (current === undefined || current === null || (typeof current === 'undefined' ? 'undefined' : _typeof(current)) !== 'object' || Array.isArray(current) && isNaN(key)) { | ||
return undefined; | ||
} | ||
current = current[key]; | ||
if (current === undefined || current === null || typeof current !== 'object' || Array.isArray(current) && isNaN(key)) { | ||
return undefined; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
current = current[key]; | ||
} | ||
@@ -63,2 +42,12 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var isPromise$1 = (function (obj) { | ||
return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; | ||
}); | ||
// | ||
@@ -86,9 +75,26 @@ | ||
var results = updates(next, field, values); | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
if (isPromise$1(results)) { | ||
results.then(function (resolved) { | ||
Object.keys(resolved).forEach(function (destField) { | ||
form.change(destField, resolved[destField]); | ||
}); | ||
}); | ||
} else { | ||
Object.keys(results).forEach(function (destField) { | ||
form.change(destField, results[destField]); | ||
}); | ||
} | ||
} else { | ||
Object.keys(updates).forEach(function (destField) { | ||
var update = updates[destField]; | ||
form.change(destField, update(next, values)); | ||
var result = update(next, values); | ||
if (isPromise$1(result)) { | ||
result.then(function (resolved) { | ||
form.change(destField, resolved); | ||
}); | ||
} else { | ||
form.change(destField, result); | ||
} | ||
}); | ||
@@ -95,0 +101,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t["final-form-calculate"]={})}(this,function(t){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n=function(t,n){var r=function(t){if(null===t||void 0===t)return[];if("string"!=typeof t)throw new Error("toPath() expects a string");return t.length?t.split(/[.[\]]+/).filter(Boolean):[]}(n),o=t,f=!0,i=!1,u=void 0;try{for(var a,c=r[Symbol.iterator]();!(f=(a=c.next()).done);f=!0){var l=a.value;if(void 0===o||null===o||"object"!==(void 0===o?"undefined":e(o))||Array.isArray(o)&&isNaN(l))return;o=o[l]}}catch(t){i=!0,u=t}finally{try{!f&&c.return&&c.return()}finally{if(i)throw u}}return o},r=function(t,e){return t===e};t.default=function(){for(var t=arguments.length,e=Array(t),o=0;o<t;o++)e[o]=arguments[o];return function(t){var o={};return t.subscribe(function(f){var i=f.values;t.batch(function(){var f=function(e,r,f){var u=i&&n(i,e),a=o&&n(o,e);if(!r(u,a))if("function"==typeof f){var c=f(u,e,i);Object.keys(c).forEach(function(e){t.change(e,c[e])})}else Object.keys(f).forEach(function(e){var n=f[e];t.change(e,n(u,i))})},u=t.getRegisteredFields();e.forEach(function(t){var e=t.field,n=t.isEqual,o=t.updates;if("string"==typeof e)f(e,n||r,o);else{var i=Array.isArray(e)?function(t){return~e.indexOf(t)}:function(t){return e.test(t)};u.forEach(function(t){i(t)&&f(t,n||r,o)})}}),o=i})},{values:!0})}},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t["final-form-calculate"]={})}(this,function(t){"use strict";var s=function(t,n){for(var e=function(t){if(null==t||!t.length)return[];if("string"!=typeof t)throw new Error("toPath() expects a string");return t.split(/[.[\]]+/).filter(Boolean)}(n),o=t,r=0;r<e.length;r++){var f=e[r];if(null==o||"object"!=typeof o||Array.isArray(o)&&isNaN(f))return;o=o[f]}return o},n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},l=function(t){return!!t&&("object"===(void 0===t?"undefined":n(t))||"function"==typeof t)&&"function"==typeof t.then},y=function(t,n){return t===n};t.default=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return function(c){var a={};return c.subscribe(function(t){var u=t.values;c.batch(function(){var f=function(t,n,e){var o=u&&s(u,t),r=a&&s(a,t);if(!n(o,r))if("function"==typeof e){var f=e(o,t,u);l(f)?f.then(function(n){Object.keys(n).forEach(function(t){c.change(t,n[t])})}):Object.keys(f).forEach(function(t){c.change(t,f[t])})}else Object.keys(e).forEach(function(n){var t=(0,e[n])(o,u);l(t)?t.then(function(t){c.change(n,t)}):c.change(n,t)})},i=c.getRegisteredFields();n.forEach(function(t){var n=t.field,e=t.isEqual,o=t.updates;if("string"==typeof n)f(n,e||y,o);else{var r=Array.isArray(n)?function(t){return~n.indexOf(t)}:function(t){return n.test(t)};i.forEach(function(t){r(t)&&f(t,e||y,o)})}}),a=u})},{values:!0})}},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=final-form-calculate.umd.min.js.map |
{ | ||
"name": "final-form-calculate", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Decorator for calculating field values based on other field values in 🏁 Final Form", | ||
@@ -28,36 +28,36 @@ "main": "dist/final-form-calculate.cjs.js", | ||
"devDependencies": { | ||
"babel-eslint": "^8.2.2", | ||
"babel-jest": "^22.4.1", | ||
"babel-eslint": "^8.2.3", | ||
"babel-jest": "^23.0.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"bundlesize": "^0.16.0", | ||
"bundlesize": "^0.17.0", | ||
"doctoc": "^1.3.1", | ||
"eslint": "^4.19.0", | ||
"eslint": "^4.19.1", | ||
"eslint-config-react-app": "^2.1.0", | ||
"eslint-plugin-babel": "^4.1.2", | ||
"eslint-plugin-flowtype": "^2.46.1", | ||
"eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-babel": "^5.1.0", | ||
"eslint-plugin-flowtype": "^2.49.3", | ||
"eslint-plugin-import": "^2.12.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.7.0", | ||
"final-form": "^4.3.1", | ||
"eslint-plugin-react": "^7.9.1", | ||
"final-form": "^4.8.1", | ||
"flow": "^0.2.3", | ||
"flow-bin": "^0.68.0", | ||
"flow-bin": "^0.74.0", | ||
"glow": "^1.2.2", | ||
"husky": "^0.14.3", | ||
"jest": "^22.4.2", | ||
"lint-staged": "^7.0.0", | ||
"nps": "^5.8.2", | ||
"jest": "^23.1.0", | ||
"lint-staged": "^7.1.3", | ||
"nps": "^5.9.0", | ||
"nps-utils": "^1.5.0", | ||
"prettier": "^1.11.1", | ||
"prettier": "^1.13.5", | ||
"prettier-eslint-cli": "^4.7.1", | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"rollup-plugin-commonjs": "^9.1.0", | ||
"rollup": "^0.60.1", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-flow": "^1.1.1", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"typescript": "^2.7.2" | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"typescript": "^2.9.1" | ||
}, | ||
@@ -64,0 +64,0 @@ "peerDependencies": { |
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
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
14
23067
310