@uform/core
Advanced tools
Comparing version 0.1.0-alpha.6 to 0.1.0-alpha.7
@@ -5,5 +5,9 @@ "use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports.Field = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _utils = require("./utils"); | ||
@@ -19,6 +23,2 @@ | ||
var isValid = function isValid(val) { | ||
return val !== undefined; | ||
}; | ||
var Field = | ||
@@ -50,3 +50,3 @@ /*#__PURE__*/ | ||
if (isValid(options.initialValue)) { | ||
if (!(0, _utils.isEmpty)(options.initialValue)) { | ||
this.initialValue = (0, _utils.clone)(options.initialValue); | ||
@@ -59,9 +59,9 @@ } | ||
this.name = isValid(options.name) ? options.name : this.name; | ||
this.name = !(0, _utils.isEmpty)(options.name) ? options.name : this.name || ''; | ||
this.namePath = (0, _utils.resolveFieldPath)(this.name); | ||
this.editable = this.getEditable(options.editable); | ||
this.path = (0, _utils.resolveFieldPath)(isValid(options.path) ? options.path : this.path); | ||
this.rules = isValid(options.rules) ? (0, _utils.clone)(options.rules) : this.rules; | ||
this.path = (0, _utils.resolveFieldPath)(!(0, _utils.isEmpty)(options.path) ? options.path : this.path || []); | ||
this.rules = !(0, _utils.isEmpty)(options.rules) ? (0, _utils.clone)(options.rules) : this.rules; | ||
this.required = (0, _utils.hasRequired)(this.rules); | ||
this.props = (0, _utils.clone)(isValid(options.props) ? options.props : this.props, filterSchema); | ||
this.props = (0, _utils.isEmpty)(options.props) ? (0, _utils.clone)(this.props, filterSchema) : (0, _utils.clone)((0, _extends2.default)({}, this.props, options.props), filterSchema); | ||
@@ -68,0 +68,0 @@ if ((0, _utils.isFn)(options.onChange)) { |
{ | ||
"name": "@uform/core", | ||
"version": "0.1.0-alpha.6", | ||
"version": "0.1.0-alpha.7", | ||
"license": "MIT", | ||
@@ -18,4 +18,4 @@ "main": "lib", | ||
"dependencies": { | ||
"@uform/utils": "^0.1.0-alpha.5", | ||
"@uform/validator": "^0.1.0-alpha.5", | ||
"@uform/utils": "^0.1.0-alpha.7", | ||
"@uform/validator": "^0.1.0-alpha.7", | ||
"dot-match": "^0.1.18", | ||
@@ -29,3 +29,3 @@ "immer": "^1.7.4", | ||
}, | ||
"gitHead": "241ba45f1726e2f08ae5f32c11702e7bc69fd96b" | ||
"gitHead": "eac700af0f1b9b39281d4963eb82d66b280aed3c" | ||
} |
@@ -10,3 +10,4 @@ import { | ||
hasRequired, | ||
resolveFieldPath | ||
resolveFieldPath, | ||
isEmpty | ||
} from './utils' | ||
@@ -19,4 +20,2 @@ import produce, { setAutoFreeze } from 'immer' | ||
const isValid = val => val !== undefined | ||
export class Field { | ||
@@ -43,3 +42,3 @@ constructor(context, options) { | ||
this.value = options.value | ||
if (isValid(options.initialValue)) { | ||
if (!isEmpty(options.initialValue)) { | ||
this.initialValue = clone(options.initialValue) | ||
@@ -51,15 +50,14 @@ } | ||
} | ||
this.name = isValid(options.name) ? options.name : this.name | ||
this.name = !isEmpty(options.name) ? options.name : this.name || '' | ||
this.namePath = resolveFieldPath(this.name) | ||
this.editable = this.getEditable(options.editable) | ||
this.path = resolveFieldPath( | ||
isValid(options.path) ? options.path : this.path | ||
!isEmpty(options.path) ? options.path : this.path || [] | ||
) | ||
this.rules = isValid(options.rules) ? clone(options.rules) : this.rules | ||
this.rules = !isEmpty(options.rules) ? clone(options.rules) : this.rules | ||
this.required = hasRequired(this.rules) | ||
this.props = clone( | ||
isValid(options.props) ? options.props : this.props, | ||
filterSchema | ||
) | ||
this.props = isEmpty(options.props) | ||
? clone(this.props, filterSchema) | ||
: clone({ ...this.props, ...options.props }, filterSchema) | ||
@@ -66,0 +64,0 @@ if (isFn(options.onChange)) { |
69158
2128