fix getHotvalue

This commit is contained in:
kangwei 2020-05-09 17:34:02 +08:00
parent 9bf2e3b4ef
commit f28785d53c
5 changed files with 15 additions and 17 deletions

View File

@ -3,6 +3,7 @@ import { Transducer } from './utils';
import { SettingPropEntry } from './setting-prop-entry';
import { SettingEntry } from './setting-entry';
import { computed, obx } from '@ali/lowcode-editor-core';
import { cloneDeep } from '@ali/lowcode-utils';
export class SettingField extends SettingPropEntry implements SettingEntry {
readonly isSettingField = true;
@ -118,7 +119,8 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
// ======= compatibles for vision ======
getHotValue(): any {
let v = this.getValue();
// avoid View modify
let v = cloneDeep(this.getValue());
if (v == null) {
v = this.extraProps.defaultValue;
}
@ -127,6 +129,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
setHotValue(data: any) {
this.setValue(this.transducer.toNative(data));
this.valueChange();
}
onEffect(action: () => void): () => void {

View File

@ -62,14 +62,6 @@ export class SettingPropEntry implements SettingEntry {
this.isSingle = parent.isSingle;
this.designer = parent.designer;
this.top = parent.top;
autorun(({ firstRun }) => {
const value = this.getValue();
if (firstRun) {
return;
}
this.emitter.emit('valuechange', value);
});
}
getId() {
@ -180,11 +172,11 @@ export class SettingPropEntry implements SettingEntry {
return this.top;
}
// add settingfield props
// add settingfield props
get props() {
return this.top;
}
onValueChange(func: () => any) {
this.emitter.on('valuechange', func);
@ -197,8 +189,6 @@ export class SettingPropEntry implements SettingEntry {
* @deprecated
*/
valueChange() {
console.warn('valueChange deprecated');
this.emitter.emit('valuechange');
}

View File

@ -217,6 +217,10 @@ export class NodeChildren {
return this.children.some((child, index) => fn(child, index));
}
filter(fn: (item: Node, index: number) => item is Node) {
return this.children.filter(fn);
}
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
let changed = false;
if (remover) {

View File

@ -18,8 +18,8 @@
"@ali/lowcode-types": "^0.8.2",
"@ali/lowcode-utils": "^0.8.3",
"@alifd/next": "^1.19.16",
"@recore/obx": "^1.0.8",
"@recore/obx-react": "^1.0.7",
"@recore/obx": "^1.0.9",
"@recore/obx-react": "^1.0.8",
"classnames": "^2.2.6",
"debug": "^4.1.1",
"intl-messageformat": "^8.3.1",

View File

@ -122,9 +122,10 @@ export default class Engine extends PureComponent {
const originRender = Component.prototype.render;
Component.prototype.render = function () {
if (this.state && this.state.engineRenderError) {
return engine.createElement(this.getFaultComponent(), {
this.state.engineRenderError = false;
return engine.createElement(engine.getFaultComponent(), {
...this.props,
error: this.state.error,
props: this.props,
});
}
return originRender.call(this);