Comparing version 3.0.0-rc.3 to 3.0.0-rc.4
/// <reference types="react" /> | ||
import { BaseForm } from './BaseForm'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
import { DeepPartial, ModelTransformMode } from './types'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
@@ -6,0 +6,0 @@ onChangeModel?(model: DeepPartial<Model>): void; |
@@ -36,4 +36,5 @@ "use strict"; | ||
this.setState(function (state) { return ({ model: setWith_1.default(clone_1.default(state.model), key, value, clone_1.default) }); }, function () { | ||
if (_this.props.onChangeModel) | ||
if (_this.props.onChangeModel) { | ||
_this.props.onChangeModel(_this.state.model); | ||
} | ||
}); | ||
@@ -40,0 +41,0 @@ }; |
@@ -5,3 +5,2 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var react_1 = tslib_1.__importStar(require("react")); | ||
var clone_1 = tslib_1.__importDefault(require("lodash/clone")); | ||
@@ -11,2 +10,3 @@ var get_1 = tslib_1.__importDefault(require("lodash/get")); | ||
var setWith_1 = tslib_1.__importDefault(require("lodash/setWith")); | ||
var react_1 = tslib_1.__importStar(require("react")); | ||
var changedKeys_1 = require("./changedKeys"); | ||
@@ -13,0 +13,0 @@ var context_1 = require("./context"); |
@@ -9,11 +9,14 @@ "use strict"; | ||
function changedKeys(root, valueA, valueB) { | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) { | ||
return isEqual_1.default(valueA, valueB) ? [] : [root]; | ||
if (!valueB) | ||
} | ||
if (!valueB) { | ||
return tslib_1.__spreadArrays([root], Object.keys(valueA).map(function (key) { return joinName_1.joinName(root, key); })); | ||
} | ||
var changed = xorWith_1.default(Object.entries(valueA), Object.entries(valueB), isEqual_1.default).map(function (pair) { return joinName_1.joinName(root, pair[0]); }); | ||
if (changed.length) | ||
if (changed.length) { | ||
changed.unshift(root); | ||
} | ||
return changed; | ||
} | ||
exports.changedKeys = changedKeys; |
@@ -5,5 +5,5 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var react_1 = tslib_1.__importDefault(require("react")); | ||
var mapValues_1 = tslib_1.__importDefault(require("lodash/mapValues")); | ||
var some_1 = tslib_1.__importDefault(require("lodash/some")); | ||
var react_1 = tslib_1.__importDefault(require("react")); | ||
var context_1 = require("./context"); | ||
@@ -10,0 +10,0 @@ var useField_1 = require("./useField"); |
@@ -40,2 +40,3 @@ "use strict"; | ||
var placeholder = propagate(props.placeholder, schemaProps.placeholder, state.placeholder, label || labelFallback)[0]; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
var id = react_1.useMemo(function () { return context.randomId(); }, []); | ||
@@ -45,3 +46,5 @@ var onChange = react_1.useCallback(function (value, key) { | ||
context.onChange(key, value); | ||
}, [context.onChange, name]); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[context.onChange, name]); | ||
var valueFromModel = get_1.default(context.model, name); | ||
@@ -58,2 +61,3 @@ var initialValue; | ||
if ((options === null || options === void 0 ? void 0 : options.initialValue) !== false) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
react_1.useEffect(function () { | ||
@@ -65,2 +69,3 @@ var _a; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
@@ -67,0 +72,0 @@ } |
/// <reference types="react" /> | ||
import { BaseForm } from './BaseForm'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
import { DeepPartial, ModelTransformMode } from './types'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
@@ -6,0 +6,0 @@ onChangeModel?(model: DeepPartial<Model>): void; |
@@ -29,4 +29,5 @@ import clone from 'lodash/clone'; | ||
this.setState(state => ({ model: setWith(clone(state.model), key, value, clone) }), () => { | ||
if (this.props.onChangeModel) | ||
if (this.props.onChangeModel) { | ||
this.props.onChangeModel(this.state.model); | ||
} | ||
}); | ||
@@ -33,0 +34,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import React, { Component } from 'react'; | ||
import clone from 'lodash/clone'; | ||
@@ -6,2 +5,3 @@ import get from 'lodash/get'; | ||
import setWith from 'lodash/setWith'; | ||
import React, { Component } from 'react'; | ||
import { changedKeys } from './changedKeys'; | ||
@@ -8,0 +8,0 @@ import { context } from './context'; |
@@ -5,10 +5,13 @@ import isEqual from 'lodash/isEqual'; | ||
export function changedKeys(root, valueA, valueB) { | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) { | ||
return isEqual(valueA, valueB) ? [] : [root]; | ||
if (!valueB) | ||
} | ||
if (!valueB) { | ||
return [root, ...Object.keys(valueA).map(key => joinName(root, key))]; | ||
} | ||
const changed = xorWith(Object.entries(valueA), Object.entries(valueB), isEqual).map(pair => joinName(root, pair[0])); | ||
if (changed.length) | ||
if (changed.length) { | ||
changed.unshift(root); | ||
} | ||
return changed; | ||
} |
@@ -1,4 +0,4 @@ | ||
import React from 'react'; | ||
import mapValues from 'lodash/mapValues'; | ||
import some from 'lodash/some'; | ||
import React from 'react'; | ||
import { context as contextReference } from './context'; | ||
@@ -5,0 +5,0 @@ import { useField } from './useField'; |
@@ -36,6 +36,9 @@ import get from 'lodash/get'; | ||
const [placeholder] = propagate(props.placeholder, schemaProps.placeholder, state.placeholder, label || labelFallback); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const id = useMemo(() => context.randomId(), []); | ||
const onChange = useCallback((value, key = name) => { | ||
context.onChange(key, value); | ||
}, [context.onChange, name]); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[context.onChange, name]); | ||
const valueFromModel = get(context.model, name); | ||
@@ -52,2 +55,3 @@ let initialValue; | ||
if ((options === null || options === void 0 ? void 0 : options.initialValue) !== false) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useEffect(() => { | ||
@@ -59,2 +63,3 @@ var _a; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
@@ -61,0 +66,0 @@ } |
{ | ||
"name": "uniforms", | ||
"version": "3.0.0-rc.3", | ||
"version": "3.0.0-rc.4", | ||
"license": "MIT", | ||
@@ -35,3 +35,3 @@ "main": "es5/index.js", | ||
}, | ||
"gitHead": "ecdb0297c75ea20fccf95b73c8ab63d9c583a500" | ||
"gitHead": "606afa97d8cd6952d2622c47c79786f6a662a2e4" | ||
} |
@@ -7,6 +7,8 @@ import isEqual from 'lodash/isEqual'; | ||
export function changedKeys<T>(root: string, valueA?: T, valueB?: T) { | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) { | ||
return isEqual(valueA, valueB) ? [] : [root]; | ||
if (!valueB) | ||
} | ||
if (!valueB) { | ||
return [root, ...Object.keys(valueA).map(key => joinName(root, key))]; | ||
} | ||
@@ -19,4 +21,6 @@ const changed = xorWith( | ||
if (changed.length) changed.unshift(root); | ||
if (changed.length) { | ||
changed.unshift(root); | ||
} | ||
return changed; | ||
} |
import invariant from 'invariant'; | ||
import { useContext } from 'react'; | ||
import { context as contextReference } from './context'; | ||
import { Context } from './types'; | ||
import { context as contextReference } from './context'; | ||
@@ -7,0 +7,0 @@ export function useForm<Model>(): Context<Model> { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
188230
4330