runningTree在getOperation时增加对父结点影响的处理
This commit is contained in:
parent
f21d15baaa
commit
c2dd26e6b3
|
|
@ -171,7 +171,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
|
|||
update(data: ED[T]['Update']['data'], action?: ED[T]['Action']): void;
|
||||
remove(): void;
|
||||
setDirty(): void;
|
||||
composeOperations(): Array<{
|
||||
composeOperations(fromParent?: boolean): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
}> | undefined;
|
||||
|
|
|
|||
|
|
@ -626,17 +626,27 @@ class ListNode extends Node {
|
|||
if (!this.dirty) {
|
||||
return;
|
||||
}
|
||||
const parentFilter = this.parent instanceof SingleNode && this.parent.getParentFilter(this);
|
||||
const operations = [];
|
||||
for (const id in this.updates) {
|
||||
if (this.updates[id]) {
|
||||
const operation = cloneDeep(this.updates[id]);
|
||||
if (parentFilter) {
|
||||
if (operation.action === 'create') {
|
||||
Object.assign(operation.data, parentFilter);
|
||||
}
|
||||
else {
|
||||
operation.filter = combineFilters(this.entity, this.schema, [operation.filter, parentFilter]);
|
||||
}
|
||||
}
|
||||
operations.push({
|
||||
entity: this.entity,
|
||||
operation: cloneDeep(this.updates[id]),
|
||||
operation,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const id in this.children) {
|
||||
const childOperation = this.children[id].composeOperations();
|
||||
const childOperation = this.children[id].composeOperations(true);
|
||||
if (childOperation) {
|
||||
// 现在因为后台有not null检查,不能先create再update,所以还是得合并成一个
|
||||
assert(childOperation.length === 1);
|
||||
|
|
@ -1122,15 +1132,21 @@ class SingleNode extends Node {
|
|||
}
|
||||
super.setDirty();
|
||||
}
|
||||
composeOperations() {
|
||||
composeOperations(fromParent) {
|
||||
if (this.dirty) {
|
||||
// 如果父亲是一个list,这里可能是create出来的新结点,要到parent上获取create动作
|
||||
if (this.parent instanceof ListNode && !fromParent) {
|
||||
const operations = this.parent.composeOperations();
|
||||
return operations.filter(ele => ele.operation.action === 'create' && ele.operation.data.id === this.id ||
|
||||
ele.operation.filter.id === this.id);
|
||||
}
|
||||
const operation = this.operation && cloneDeep(this.operation);
|
||||
if (operation) {
|
||||
operation.filter = this.getFilter();
|
||||
for (const ele in this.children) {
|
||||
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
const child = this.children[ele];
|
||||
const childOperations = child.composeOperations();
|
||||
const childOperations = child.composeOperations(true);
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
|
|
@ -1479,7 +1495,7 @@ class VirtualNode extends Feature {
|
|||
const operationss = [];
|
||||
const operationDict = {};
|
||||
for (const ele in this.children) {
|
||||
const operation = this.children[ele].composeOperations();
|
||||
const operation = this.children[ele].composeOperations(true);
|
||||
if (operation) {
|
||||
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
if (operationDict[idx]) {
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
|
|||
update(data: ED[T]['Update']['data'], action?: ED[T]['Action']): void;
|
||||
remove(): void;
|
||||
setDirty(): void;
|
||||
composeOperations(): Array<{
|
||||
composeOperations(fromParent?: boolean): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
}> | undefined;
|
||||
|
|
|
|||
|
|
@ -629,17 +629,27 @@ class ListNode extends Node {
|
|||
if (!this.dirty) {
|
||||
return;
|
||||
}
|
||||
const parentFilter = this.parent instanceof SingleNode && this.parent.getParentFilter(this);
|
||||
const operations = [];
|
||||
for (const id in this.updates) {
|
||||
if (this.updates[id]) {
|
||||
const operation = (0, lodash_1.cloneDeep)(this.updates[id]);
|
||||
if (parentFilter) {
|
||||
if (operation.action === 'create') {
|
||||
Object.assign(operation.data, parentFilter);
|
||||
}
|
||||
else {
|
||||
operation.filter = (0, filter_1.combineFilters)(this.entity, this.schema, [operation.filter, parentFilter]);
|
||||
}
|
||||
}
|
||||
operations.push({
|
||||
entity: this.entity,
|
||||
operation: (0, lodash_1.cloneDeep)(this.updates[id]),
|
||||
operation,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const id in this.children) {
|
||||
const childOperation = this.children[id].composeOperations();
|
||||
const childOperation = this.children[id].composeOperations(true);
|
||||
if (childOperation) {
|
||||
// 现在因为后台有not null检查,不能先create再update,所以还是得合并成一个
|
||||
(0, assert_1.assert)(childOperation.length === 1);
|
||||
|
|
@ -1125,15 +1135,21 @@ class SingleNode extends Node {
|
|||
}
|
||||
super.setDirty();
|
||||
}
|
||||
composeOperations() {
|
||||
composeOperations(fromParent) {
|
||||
if (this.dirty) {
|
||||
// 如果父亲是一个list,这里可能是create出来的新结点,要到parent上获取create动作
|
||||
if (this.parent instanceof ListNode && !fromParent) {
|
||||
const operations = this.parent.composeOperations();
|
||||
return operations.filter(ele => ele.operation.action === 'create' && ele.operation.data.id === this.id ||
|
||||
ele.operation.filter.id === this.id);
|
||||
}
|
||||
const operation = this.operation && (0, lodash_1.cloneDeep)(this.operation);
|
||||
if (operation) {
|
||||
operation.filter = this.getFilter();
|
||||
for (const ele in this.children) {
|
||||
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
const child = this.children[ele];
|
||||
const childOperations = child.composeOperations();
|
||||
const childOperations = child.composeOperations(true);
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
(0, assert_1.assert)(childOperations.length === 1);
|
||||
|
|
@ -1482,7 +1498,7 @@ class VirtualNode extends Feature_1.Feature {
|
|||
const operationss = [];
|
||||
const operationDict = {};
|
||||
for (const ele in this.children) {
|
||||
const operation = this.children[ele].composeOperations();
|
||||
const operation = this.children[ele].composeOperations(true);
|
||||
if (operation) {
|
||||
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
if (operationDict[idx]) {
|
||||
|
|
|
|||
|
|
@ -779,19 +779,29 @@ class ListNode<
|
|||
return;
|
||||
}
|
||||
|
||||
const parentFilter = this.parent instanceof SingleNode && this.parent.getParentFilter<T>(this as any);
|
||||
const operations: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation'] }> = [];
|
||||
|
||||
for (const id in this.updates) {
|
||||
if (this.updates[id]) {
|
||||
const operation = cloneDeep(this.updates[id]);
|
||||
if (parentFilter) {
|
||||
if (operation.action === 'create') {
|
||||
Object.assign(operation.data, parentFilter);
|
||||
}
|
||||
else {
|
||||
operation.filter = combineFilters(this.entity, this.schema, [operation.filter, parentFilter]);
|
||||
}
|
||||
}
|
||||
operations.push({
|
||||
entity: this.entity,
|
||||
operation: cloneDeep(this.updates[id]),
|
||||
operation,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const id in this.children) {
|
||||
const childOperation = this.children[id].composeOperations();
|
||||
const childOperation = this.children[id].composeOperations(true);
|
||||
if (childOperation) {
|
||||
// 现在因为后台有not null检查,不能先create再update,所以还是得合并成一个
|
||||
assert(childOperation.length === 1);
|
||||
|
|
@ -1354,19 +1364,28 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
super.setDirty();
|
||||
}
|
||||
|
||||
composeOperations(): Array<{
|
||||
composeOperations(fromParent?: boolean): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
}> | undefined {
|
||||
if (this.dirty) {
|
||||
const operation = this.operation && cloneDeep(this.operation);
|
||||
// 如果父亲是一个list,这里可能是create出来的新结点,要到parent上获取create动作
|
||||
if (this.parent instanceof ListNode && !fromParent) {
|
||||
const operations = this.parent.composeOperations();
|
||||
|
||||
return operations!.filter(
|
||||
ele => ele.operation.action === 'create' && (ele.operation.data as ED[keyof ED]['CreateSingle']['data']).id === this.id ||
|
||||
ele.operation.filter!.id === this.id
|
||||
)!;
|
||||
}
|
||||
|
||||
const operation = this.operation && cloneDeep(this.operation);
|
||||
if (operation) {
|
||||
operation.filter = this.getFilter();
|
||||
for (const ele in this.children) {
|
||||
const ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
const child = this.children[ele];
|
||||
const childOperations = child!.composeOperations();
|
||||
const childOperations = child!.composeOperations(true);
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
|
|
@ -1746,7 +1765,7 @@ class VirtualNode<
|
|||
const operationss = [];
|
||||
const operationDict: Record<string, any> = {};
|
||||
for (const ele in this.children) {
|
||||
const operation = this.children[ele].composeOperations();
|
||||
const operation = this.children[ele].composeOperations(true);
|
||||
if (operation) {
|
||||
const idx = ele.indexOf(':') !== -1 ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
if (operationDict[idx]) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue