@uform/core
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -24,4 +24,2 @@ "use strict"; | ||
var _immer = _interopRequireDefault(require("immer")); | ||
var defaults = function defaults(opts) { | ||
@@ -104,9 +102,7 @@ return (0, _extends2["default"])({ | ||
if (!(0, _utils.isFn)(reducer)) return; | ||
return new Promise(function (resolve) { | ||
var published = (0, _immer["default"])(_this.publishState(), reducer); | ||
_this.checkState(published); | ||
var published = _this.publishState(); | ||
resolve(); | ||
}); | ||
reducer(published, reducer); | ||
return Promise.resolve(_this.checkState(published)); | ||
}); | ||
@@ -203,3 +199,3 @@ this.options = defaults(opts); | ||
this.state.dirty = true; | ||
this.updateFieldsValue(); | ||
return this.updateFieldsValue(); | ||
} | ||
@@ -210,3 +206,3 @@ | ||
this.state.dirty = true; | ||
this.updateFieldInitialValue(); | ||
return this.updateFieldInitialValue(); | ||
} | ||
@@ -531,3 +527,8 @@ }; | ||
var _defer = (0, _utils.defer)(), | ||
promise = _defer.promise, | ||
resolve = _defer.resolve; | ||
var update = function update() { | ||
var updateList = []; | ||
(0, _utils.each)(_this11.fields, function (field, name) { | ||
@@ -541,10 +542,15 @@ var newValue = _this11.getValue(name); | ||
if (field.dirty) { | ||
(0, _utils.raf)(function () { | ||
if (_this11.destructed) return; | ||
field.notify(); | ||
updateList.push(new Promise(function (resolve) { | ||
(0, _utils.raf)(function () { | ||
if (_this11.destructed) return; | ||
field.notify(); | ||
_this11.triggerEffect('onFieldChange', field.publishState()); | ||
}); | ||
_this11.triggerEffect('onFieldChange', field.publishState()); | ||
resolve(); | ||
}); | ||
})); | ||
} | ||
}); | ||
resolve(Promise.all(updateList)); | ||
}; | ||
@@ -563,2 +569,4 @@ | ||
} | ||
return promise; | ||
}; | ||
@@ -565,0 +573,0 @@ |
{ | ||
"name": "@uform/core", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"license": "MIT", | ||
@@ -18,6 +18,5 @@ "main": "lib", | ||
"dependencies": { | ||
"@uform/utils": "0.1.1", | ||
"@uform/validator": "0.1.1", | ||
"@uform/utils": "0.1.2", | ||
"@uform/validator": "0.1.2", | ||
"dot-match": "^0.1.18", | ||
"immer": "^1.7.4", | ||
"rxjs": "^6.3.3", | ||
@@ -29,3 +28,3 @@ "scheduler": "^0.11.2" | ||
}, | ||
"gitHead": "66a0d1244dbef169c5dde669bef7f1277b0cab10" | ||
"gitHead": "18388943ac8f979c274ec297534b025a24127dad" | ||
} |
@@ -20,3 +20,4 @@ import { | ||
getSchemaNodeFromPath, | ||
BufferList | ||
BufferList, | ||
defer | ||
} from './utils' | ||
@@ -28,3 +29,2 @@ import { Field } from './field' | ||
import { FormPath } from './path' | ||
import produce from 'immer' | ||
@@ -172,7 +172,5 @@ const defaults = opts => ({ | ||
if (!isFn(reducer)) return | ||
return new Promise(resolve => { | ||
const published = produce(this.publishState(), reducer) | ||
this.checkState(published) | ||
resolve() | ||
}) | ||
const published = this.publishState() | ||
reducer(published, reducer) | ||
return Promise.resolve(this.checkState(published)) | ||
} | ||
@@ -184,3 +182,3 @@ | ||
this.state.dirty = true | ||
this.updateFieldsValue() | ||
return this.updateFieldsValue() | ||
} | ||
@@ -190,3 +188,3 @@ if (!isEqual(this.state.initialValues, published.initialValues)) { | ||
this.state.dirty = true | ||
this.updateFieldInitialValue() | ||
return this.updateFieldInitialValue() | ||
} | ||
@@ -446,3 +444,6 @@ } | ||
updateFieldsValue(validate = true) { | ||
const { promise, resolve } = defer() | ||
const update = () => { | ||
const updateList = [] | ||
each(this.fields, (field, name) => { | ||
@@ -454,9 +455,15 @@ let newValue = this.getValue(name) | ||
if (field.dirty) { | ||
raf(() => { | ||
if (this.destructed) return | ||
field.notify() | ||
this.triggerEffect('onFieldChange', field.publishState()) | ||
}) | ||
updateList.push( | ||
new Promise(resolve => { | ||
raf(() => { | ||
if (this.destructed) return | ||
field.notify() | ||
this.triggerEffect('onFieldChange', field.publishState()) | ||
resolve() | ||
}) | ||
}) | ||
) | ||
} | ||
}) | ||
resolve(Promise.all(updateList)) | ||
} | ||
@@ -473,2 +480,4 @@ if (this.state.dirty && this.initialized) { | ||
} | ||
return promise | ||
} | ||
@@ -475,0 +484,0 @@ |
77966
5
2404
+ Added@uform/utils@0.1.2(transitive)
+ Added@uform/validator@0.1.2(transitive)
- Removedimmer@^1.7.4
- Removed@uform/utils@0.1.1(transitive)
- Removed@uform/validator@0.1.1(transitive)
- Removedimmer@1.12.1(transitive)
Updated@uform/utils@0.1.2
Updated@uform/validator@0.1.2