提交 900ee697 编写于 作者: A Aditya Thakral

Optimistic updates for object renderer

上级 f9dda0e6
......@@ -1035,25 +1035,30 @@ export class SettingObjectRenderer extends AbstractSettingRenderer implements IT
const defaultValue: Record<string, unknown> = template.context.defaultValue;
const scopeValue: Record<string, unknown> = template.context.scopeValue;
const newValue: Record<string, unknown> = {};
let newItems: IObjectDataItem[] = [];
template.objectWidget.items.forEach(item => {
template.objectWidget.items.forEach((item, idx) => {
// Item was updated
if (isDefined(e.item) && e.originalItem.key.data === item.key.data) {
if (isDefined(e.item) && e.targetIndex === idx) {
newValue[e.item.key.data] = e.item.value.data;
newItems.push(e.item);
}
// All remaining items
else {
// All remaining items, but skip the one that we just updated
else if (isUndefinedOrNull(e.item) || e.item.key.data !== item.key.data) {
newValue[item.key.data] = item.value.data;
newItems.push(item);
}
});
// Item was deleted
if (isUndefinedOrNull(e.item)) {
delete newValue[e.originalItem.key.data];
newItems = newItems.filter(item => item.key.data !== e.originalItem.key.data);
}
// New item was added
else if (template.objectWidget.isItemNew(e.originalItem)) {
newValue[e.item.key.data] = e.item.value.data;
newItems.push(e.item);
}
Object.entries(newValue).forEach(([key, value]) => {
......@@ -1068,6 +1073,8 @@ export class SettingObjectRenderer extends AbstractSettingRenderer implements IT
value: Object.keys(newValue).length === 0 ? undefined : newValue,
type: template.context.valueType
});
template.objectWidget.setValue(newItems);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册