Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

final-form-calculate

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final-form-calculate - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

26

dist/final-form-calculate.cjs.js

@@ -7,10 +7,4 @@ 'use strict';

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 = (function (obj) {
return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
});

@@ -23,4 +17,5 @@

};
var createDecorator = function createDecorator() {
for (var _len = arguments.length, calculations = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, calculations = new Array(_len), _key = 0; _key < _len; _key++) {
calculations[_key] = arguments[_key];

@@ -33,3 +28,2 @@ }

var values = _ref.values;
form.batch(function () {

@@ -39,5 +33,6 @@ var runUpdates = function runUpdates(field, isEqual, updates) {

var previous = previousValues && finalForm.getIn(previousValues, field);
if (!isEqual(next, previous)) {
if (typeof updates === 'function') {
var results = updates(next, field, values);
var results = updates(next, field, values, previousValues);

@@ -58,3 +53,3 @@ if (isPromise(results)) {

var update = updates[destField];
var result = update(next, values);
var result = update(next, values, previousValues);

@@ -72,2 +67,3 @@ if (isPromise(result)) {

};
var fields = form.getRegisteredFields();

@@ -84,3 +80,5 @@ calculations.forEach(function (_ref2) {

var matches = Array.isArray(field) ? function (name) {
return ~field.indexOf(name);
return ~field.indexOf(name) || field.findIndex(function (f) {
return f instanceof RegExp && f.test(name);
}) !== -1;
} : function (name) {

@@ -98,3 +96,5 @@ return field.test(name);

});
}, { values: true });
}, {
values: true
});
return unsubscribe;

@@ -101,0 +101,0 @@ };

import { getIn } from 'final-form';
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 = (function (obj) {
return !!obj && ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
});

@@ -18,4 +12,5 @@

};
var createDecorator = function createDecorator() {
for (var _len = arguments.length, calculations = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, calculations = new Array(_len), _key = 0; _key < _len; _key++) {
calculations[_key] = arguments[_key];

@@ -28,3 +23,2 @@ }

var values = _ref.values;
form.batch(function () {

@@ -34,5 +28,6 @@ var runUpdates = function runUpdates(field, isEqual, updates) {

var previous = previousValues && getIn(previousValues, field);
if (!isEqual(next, previous)) {
if (typeof updates === 'function') {
var results = updates(next, field, values);
var results = updates(next, field, values, previousValues);

@@ -53,3 +48,3 @@ if (isPromise(results)) {

var update = updates[destField];
var result = update(next, values);
var result = update(next, values, previousValues);

@@ -67,2 +62,3 @@ if (isPromise(result)) {

};
var fields = form.getRegisteredFields();

@@ -79,3 +75,5 @@ calculations.forEach(function (_ref2) {

var matches = Array.isArray(field) ? function (name) {
return ~field.indexOf(name);
return ~field.indexOf(name) || field.findIndex(function (f) {
return f instanceof RegExp && f.test(name);
}) !== -1;
} : function (name) {

@@ -93,3 +91,5 @@ return field.test(name);

});
}, { values: true });
}, {
values: true
});
return unsubscribe;

@@ -96,0 +96,0 @@ };

@@ -40,10 +40,4 @@ (function (global, factory) {

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';
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
});

@@ -56,4 +50,5 @@

};
var createDecorator = function createDecorator() {
for (var _len = arguments.length, calculations = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, calculations = new Array(_len), _key = 0; _key < _len; _key++) {
calculations[_key] = arguments[_key];

@@ -66,3 +61,2 @@ }

var values = _ref.values;
form.batch(function () {

@@ -72,5 +66,6 @@ var runUpdates = function runUpdates(field, isEqual, updates) {

var previous = previousValues && getIn(previousValues, field);
if (!isEqual(next, previous)) {
if (typeof updates === 'function') {
var results = updates(next, field, values);
var results = updates(next, field, values, previousValues);

@@ -91,3 +86,3 @@ if (isPromise$1(results)) {

var update = updates[destField];
var result = update(next, values);
var result = update(next, values, previousValues);

@@ -105,2 +100,3 @@ if (isPromise$1(result)) {

};
var fields = form.getRegisteredFields();

@@ -117,3 +113,5 @@ calculations.forEach(function (_ref2) {

var matches = Array.isArray(field) ? function (name) {
return ~field.indexOf(name);
return ~field.indexOf(name) || field.findIndex(function (f) {
return f instanceof RegExp && f.test(name);
}) !== -1;
} : function (name) {

@@ -131,3 +129,5 @@ return field.test(name);

});
}, { values: true });
}, {
values: true
});
return unsubscribe;

@@ -134,0 +134,0 @@ };

@@ -1,2 +0,2 @@

!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})});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n["final-form-calculate"]={})}(this,function(n){"use strict";var s=function(n,e){for(var t=function(n){if(null==n||!n.length)return[];if("string"!=typeof n)throw new Error("toPath() expects a string");return n.split(/[.[\]]+/).filter(Boolean)}(e),r=n,f=0;f<t.length;f++){var o=t[f];if(null==r||"object"!=typeof r||Array.isArray(r)&&isNaN(o))return;r=r[o]}return r},l=function(n){return!!n&&("object"==typeof n||"function"==typeof n)&&"function"==typeof n.then},h=function(n,e){return n===e};n.default=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return function(c){var a={};return c.subscribe(function(n){var u=n.values;c.batch(function(){var o=function(n,e,t){var r=u&&s(u,n),f=a&&s(a,n);if(!e(r,f))if("function"==typeof t){var o=t(r,n,u,a);l(o)?o.then(function(e){Object.keys(e).forEach(function(n){c.change(n,e[n])})}):Object.keys(o).forEach(function(n){c.change(n,o[n])})}else Object.keys(t).forEach(function(e){var n=(0,t[e])(r,u,a);l(n)?n.then(function(n){c.change(e,n)}):c.change(e,n)})},i=c.getRegisteredFields();e.forEach(function(n){var t=n.field,e=n.isEqual,r=n.updates;if("string"==typeof t)o(t,e||h,r);else{var f=Array.isArray(t)?function(e){return~t.indexOf(e)||-1!==t.findIndex(function(n){return n instanceof RegExp&&n.test(e)})}:function(n){return t.test(n)};i.forEach(function(n){f(n)&&o(n,e||h,r)})}}),a=u})},{values:!0})}},Object.defineProperty(n,"__esModule",{value:!0})});
//# sourceMappingURL=final-form-calculate.umd.min.js.map

@@ -8,3 +8,3 @@ import { Decorator } from 'final-form'

export type UpdatesByName = {
[FieldName: string]: (value: any, allValues?: Object) => any
[FieldName: string]: (value: any, allValues?: Object, prevValues?: Object) => any
}

@@ -16,2 +16,3 @@

allValues?: Object,
prevValues?: Object,
) => { [FieldName: string]: any }

@@ -18,0 +19,0 @@

{
"name": "final-form-calculate",
"version": "1.2.1",
"version": "1.3.0",
"description": "Decorator for calculating field values based on other field values in 🏁 Final Form",

@@ -28,36 +28,48 @@ "main": "dist/final-form-calculate.cjs.js",

"devDependencies": {
"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.7.0",
"babel-preset-stage-2": "^6.24.1",
"@babel/core": "^7.0.0",
"@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.4.2",
"bundlesize": "^0.17.0",
"doctoc": "^1.3.1",
"eslint": "^4.19.1",
"eslint-config-react-app": "^2.1.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.9.1",
"final-form": "^4.8.1",
"doctoc": "^1.4.0",
"eslint": "^5.10.0",
"eslint-config-react-app": "^3.0.5",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-flowtype": "^3.2.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"final-form": "^4.11.0",
"flow": "^0.2.3",
"flow-bin": "^0.74.0",
"flow-bin": "^0.88.0",
"glow": "^1.2.2",
"husky": "^0.14.3",
"jest": "^23.1.0",
"lint-staged": "^7.1.3",
"nps": "^5.9.0",
"nps-utils": "^1.5.0",
"prettier": "^1.13.5",
"husky": "^1.2.0",
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"nps": "^5.9.3",
"nps-utils": "^1.7.0",
"prettier": "^1.15.3",
"prettier-eslint-cli": "^4.7.1",
"rollup": "^0.60.1",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup": "^0.67.4",
"rollup-plugin-babel": "^4.1.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^4.0.0",
"typescript": "^2.9.1"
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-uglify": "^6.0.0",
"typescript": "^3.2.2"
},

@@ -64,0 +76,0 @@ "peerDependencies": {

@@ -47,2 +47,9 @@ # 🏁 Final Form Calculate

{
field: 'bar', // when the value of bar changes...
updates: {
// ...set field "foo" to previous value of bar
foo: (fooValue, allValues, prevValues) => prevValues.bar
}
},
{
field: /items\[\d+\]/, // when a field matching this pattern changes...

@@ -95,11 +102,11 @@ updates: {

* [Example](#example)
* [Calculated Fields Example](#calculated-fields-example)
* [API](#api)
* [`createDecorator: (...calculations: Calculation[]) => Decorator`](#createdecorator-calculations-calculation--decorator)
* [Types](#types)
* [`Calculation: { field: FieldPattern, updates: Updates }`](#calculation--field-fieldpattern-updates-updates-)
* [`FieldName: string`](#fieldname-string)
* [`FieldPattern: FieldName | RegExp`](#fieldpattern-fieldname--regexp)
* [`Updates: { [FieldName]: (value: any, allValues: Object) => any }`](#updates--fieldname-value-any-allvalues-object--any-)
- [Example](#example)
- [Calculated Fields Example](#calculated-fields-example)
- [API](#api)
- [`createDecorator: (...calculations: Calculation[]) => Decorator`](#createdecorator-calculations-calculation--decorator)
- [Types](#types)
- [`Calculation: { field: FieldPattern, updates: Updates }`](#calculation--field-fieldpattern-updates-updates-)
- [`FieldName: string`](#fieldname-string)
- [`FieldPattern: FieldName | RegExp`](#fieldpattern-fieldname--regexp)
- [`Updates: { [FieldName]: (value: any, allValues: Object, prevValues: Object) => any }`](#updates--fieldname-value-any-allvalues-object--any-)

@@ -138,8 +145,8 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

### `UpdatesByName: { [FieldName]: (value: any, allValues: Object) => Promise | any }`
### `UpdatesByName: { [FieldName]: (value: any, allValues: Object, prevValues: Object) => Promise | any }`
Updater functions for each calculated field.
### `UpdatesForAll: (value: any, field: string, allValues: Object) => Promise | { [FieldName]: any }`
### `UpdatesForAll: (value: any, field: string, allValues: Object, prevValues: Object) => Promise | { [FieldName]: any }`
Takes the value and name of the field that just changed, as well as all the values, and returns an object of fields and new values.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc