更正runningTree在execute后的逻辑顺序
This commit is contained in:
parent
84bac2ba66
commit
001065e6ff
|
|
@ -158,6 +158,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
|
|||
create(data: Partial<Omit<ED[T]['CreateSingle']['data'], 'id'>>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
update(data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
remove(beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
setDirty(): void;
|
||||
composeOperations(): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
|
|
|
|||
|
|
@ -760,9 +760,6 @@ class ListNode extends Node {
|
|||
}
|
||||
clean(preserveAfterExecute) {
|
||||
if (this.dirty) {
|
||||
for (const k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
const originUpdates = this.updates;
|
||||
this.updates = {};
|
||||
if (preserveAfterExecute) {
|
||||
|
|
@ -774,10 +771,16 @@ class ListNode extends Node {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (const k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
// preserveAfterExecute一定发生在execute,后面的cache会publish
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
getChildOperation(child) {
|
||||
|
|
@ -1027,51 +1030,64 @@ class SingleNode extends Node {
|
|||
};
|
||||
this.setDirty();
|
||||
}
|
||||
composeOperations() {
|
||||
if (this.dirty) {
|
||||
const operation = this.operation ? cloneDeep(this.operation.operation) : {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
setDirty() {
|
||||
if (!this.dirty) {
|
||||
// 这种情况是下面的子结点setDirty引起的连锁设置
|
||||
assert(this.id);
|
||||
this.operation = {
|
||||
operation: {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
}
|
||||
};
|
||||
assert(operation);
|
||||
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();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, {
|
||||
[ele2]: childOperations[0].operation,
|
||||
});
|
||||
}
|
||||
super.setDirty();
|
||||
}
|
||||
composeOperations() {
|
||||
if (this.dirty) {
|
||||
const operation = this.operation?.operation && cloneDeep(this.operation.operation);
|
||||
if (operation) {
|
||||
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();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, {
|
||||
[ele2]: childOperations[0].operation,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
assert(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
assert(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(child instanceof ListNode);
|
||||
const childOpers = childOperations.map(ele => ele.operation);
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
operation.data[ele2].push(...childOpers);
|
||||
assert(child instanceof ListNode);
|
||||
const childOpers = childOperations.map(ele => ele.operation);
|
||||
if (childOpers.length > 0) {
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
operation.data[ele2].push(...childOpers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation,
|
||||
}];
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation,
|
||||
}];
|
||||
}
|
||||
}
|
||||
getProjection(withDecendants) {
|
||||
|
|
@ -1168,19 +1184,21 @@ class SingleNode extends Node {
|
|||
}
|
||||
clean(preserveAfterExecute) {
|
||||
if (this.dirty) {
|
||||
for (const child in this.children) {
|
||||
this.children[child].clean(preserveAfterExecute);
|
||||
}
|
||||
if (preserveAfterExecute && this.operation?.afterExecute) {
|
||||
this.operation.operation = undefined;
|
||||
}
|
||||
else {
|
||||
this.operation = undefined;
|
||||
}
|
||||
for (const child in this.children) {
|
||||
this.children[child].clean(preserveAfterExecute);
|
||||
}
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
getFilter() {
|
||||
|
|
@ -1446,7 +1464,9 @@ class VirtualNode extends Feature {
|
|||
if (!preserveAfterExecute) {
|
||||
this.dirty = false;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
checkIfClean() {
|
||||
for (const k in this.children) {
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ declare class SingleNode<ED extends EntityDict & BaseEntityDict, T extends keyof
|
|||
create(data: Partial<Omit<ED[T]['CreateSingle']['data'], 'id'>>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
update(data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
remove(beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>): void;
|
||||
setDirty(): void;
|
||||
composeOperations(): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
|
|
|
|||
|
|
@ -880,9 +880,6 @@ var ListNode = /** @class */ (function (_super) {
|
|||
};
|
||||
ListNode.prototype.clean = function (preserveAfterExecute) {
|
||||
if (this.dirty) {
|
||||
for (var k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
var originUpdates = this.updates;
|
||||
this.updates = {};
|
||||
if (preserveAfterExecute) {
|
||||
|
|
@ -894,10 +891,16 @@ var ListNode = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (var k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
// preserveAfterExecute一定发生在execute,后面的cache会publish
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
};
|
||||
ListNode.prototype.getChildOperation = function (child) {
|
||||
|
|
@ -1200,52 +1203,66 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
};
|
||||
this.setDirty();
|
||||
};
|
||||
SingleNode.prototype.composeOperations = function () {
|
||||
var _a, _b;
|
||||
if (this.dirty) {
|
||||
var operation = this.operation ? (0, lodash_1.cloneDeep)(this.operation.operation) : {
|
||||
id: (0, uuid_1.generateNewId)(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
SingleNode.prototype.setDirty = function () {
|
||||
if (!this.dirty) {
|
||||
// 这种情况是下面的子结点setDirty引起的连锁设置
|
||||
(0, assert_1.assert)(this.id);
|
||||
this.operation = {
|
||||
operation: {
|
||||
id: (0, uuid_1.generateNewId)(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
}
|
||||
};
|
||||
(0, assert_1.assert)(operation);
|
||||
for (var ele in this.children) {
|
||||
var ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
var child = this.children[ele];
|
||||
var childOperations = child.composeOperations();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
(0, assert_1.assert)(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, (_a = {},
|
||||
_a[ele2] = childOperations[0].operation,
|
||||
_a));
|
||||
}
|
||||
_super.prototype.setDirty.call(this);
|
||||
};
|
||||
SingleNode.prototype.composeOperations = function () {
|
||||
var _a, _b;
|
||||
var _c;
|
||||
if (this.dirty) {
|
||||
var operation = ((_c = this.operation) === null || _c === void 0 ? void 0 : _c.operation) && (0, lodash_1.cloneDeep)(this.operation.operation);
|
||||
if (operation) {
|
||||
for (var ele in this.children) {
|
||||
var ele2 = ele.includes(':') ? ele.slice(0, ele.indexOf(':')) : ele;
|
||||
var child = this.children[ele];
|
||||
var childOperations = child.composeOperations();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
(0, assert_1.assert)(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, (_a = {},
|
||||
_a[ele2] = childOperations[0].operation,
|
||||
_a));
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
(0, assert_1.assert)(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
(0, assert_1.assert)(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
(0, assert_1.assert)(child instanceof ListNode);
|
||||
var childOpers = childOperations.map(function (ele) { return ele.operation; });
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
(_b = operation.data[ele2]).push.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(childOpers), false));
|
||||
(0, assert_1.assert)(child instanceof ListNode);
|
||||
var childOpers = childOperations.map(function (ele) { return ele.operation; });
|
||||
if (childOpers.length > 0) {
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
(_b = operation.data[ele2]).push.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(childOpers), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation: operation,
|
||||
}];
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation: operation,
|
||||
}];
|
||||
}
|
||||
};
|
||||
SingleNode.prototype.getProjection = function (withDecendants) {
|
||||
|
|
@ -1359,19 +1376,21 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
SingleNode.prototype.clean = function (preserveAfterExecute) {
|
||||
var _a;
|
||||
if (this.dirty) {
|
||||
for (var child in this.children) {
|
||||
this.children[child].clean(preserveAfterExecute);
|
||||
}
|
||||
if (preserveAfterExecute && ((_a = this.operation) === null || _a === void 0 ? void 0 : _a.afterExecute)) {
|
||||
this.operation.operation = undefined;
|
||||
}
|
||||
else {
|
||||
this.operation = undefined;
|
||||
}
|
||||
for (var child in this.children) {
|
||||
this.children[child].clean(preserveAfterExecute);
|
||||
}
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
};
|
||||
SingleNode.prototype.getFilter = function () {
|
||||
|
|
@ -1696,7 +1715,9 @@ var VirtualNode = /** @class */ (function (_super) {
|
|||
if (!preserveAfterExecute) {
|
||||
this.dirty = false;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
};
|
||||
VirtualNode.prototype.checkIfClean = function () {
|
||||
for (var k in this.children) {
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class ListNode<
|
|||
Cxt extends AsyncContext<ED>,
|
||||
FrontCxt extends SyncContext<ED>,
|
||||
AD extends CommonAspectDict<ED, Cxt>
|
||||
> extends Node<ED, T, Cxt, FrontCxt, AD> {
|
||||
> extends Node<ED, T, Cxt, FrontCxt, AD> {
|
||||
private children: Record<string, SingleNode<ED, T, Cxt, FrontCxt, AD>>;
|
||||
private updates: Record<
|
||||
string,
|
||||
|
|
@ -968,10 +968,6 @@ class ListNode<
|
|||
|
||||
clean(preserveAfterExecute?: true) {
|
||||
if (this.dirty) {
|
||||
for (const k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
|
||||
const originUpdates = this.updates;
|
||||
this.updates = {};
|
||||
if (preserveAfterExecute) {
|
||||
|
|
@ -983,10 +979,17 @@ class ListNode<
|
|||
}
|
||||
}
|
||||
}
|
||||
for (const k in this.children) {
|
||||
this.children[k].clean(preserveAfterExecute);
|
||||
}
|
||||
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
}
|
||||
this.publish();
|
||||
else {
|
||||
// preserveAfterExecute一定发生在execute,后面的cache会publish
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1281,57 +1284,71 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
this.setDirty();
|
||||
}
|
||||
|
||||
setDirty(): void {
|
||||
if (!this.dirty) {
|
||||
// 这种情况是下面的子结点setDirty引起的连锁设置
|
||||
assert(this.id);
|
||||
this.operation = {
|
||||
operation: {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.setDirty();
|
||||
}
|
||||
|
||||
composeOperations(): Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
}> | undefined {
|
||||
if (this.dirty) {
|
||||
const operation: ED[T]['Operation'] = this.operation ? cloneDeep(this.operation.operation!) : {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
};
|
||||
assert(operation);
|
||||
const operation = this.operation?.operation && cloneDeep(this.operation.operation!);
|
||||
|
||||
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();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, {
|
||||
[ele2]: childOperations[0].operation,
|
||||
});
|
||||
if (operation) {
|
||||
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();
|
||||
if (childOperations) {
|
||||
if (child instanceof SingleNode) {
|
||||
assert(childOperations.length === 1);
|
||||
if (!operation.data[ele2]) {
|
||||
Object.assign(operation.data, {
|
||||
[ele2]: childOperations[0].operation,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
assert(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 目前应该只允许一种情况,就是父create,子update
|
||||
assert(operation.data[ele2].action === 'create' && childOperations[0].operation.action === 'update');
|
||||
Object.assign(operation.data[ele2].data, childOperations[0].operation.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(child instanceof ListNode);
|
||||
const childOpers = childOperations.map(
|
||||
ele => ele.operation
|
||||
);
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
operation.data[ele2].push(...childOpers);
|
||||
assert(child instanceof ListNode);
|
||||
const childOpers = childOperations.map(
|
||||
ele => ele.operation
|
||||
);
|
||||
if (childOpers.length > 0) {
|
||||
if (!operation.data[ele2]) {
|
||||
operation.data[ele2] = childOpers;
|
||||
}
|
||||
else {
|
||||
operation.data[ele2].push(...childOpers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation,
|
||||
}];
|
||||
}
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation,
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1431,21 +1448,22 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
|
||||
clean(preserveAfterExecute?: true) {
|
||||
if (this.dirty) {
|
||||
for (const child in this.children) {
|
||||
this.children[child]!.clean(preserveAfterExecute);
|
||||
}
|
||||
|
||||
if (preserveAfterExecute && this.operation?.afterExecute) {
|
||||
this.operation.operation = undefined;
|
||||
}
|
||||
else {
|
||||
this.operation = undefined;
|
||||
}
|
||||
for (const child in this.children) {
|
||||
this.children[child]!.clean(preserveAfterExecute);
|
||||
}
|
||||
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = undefined;
|
||||
this.dirty = undefined;
|
||||
}
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1596,7 +1614,7 @@ class VirtualNode<
|
|||
Cxt extends AsyncContext<ED>,
|
||||
FrontCxt extends SyncContext<ED>,
|
||||
AD extends CommonAspectDict<ED, Cxt>
|
||||
> extends Feature {
|
||||
> extends Feature {
|
||||
private dirty: boolean;
|
||||
private executing: boolean;
|
||||
private loading = false;
|
||||
|
|
@ -1734,9 +1752,11 @@ class VirtualNode<
|
|||
this.children[ele].clean(preserveAfterExecute);
|
||||
}
|
||||
if (!preserveAfterExecute) {
|
||||
this.dirty = false;
|
||||
this.dirty = false;
|
||||
}
|
||||
else {
|
||||
this.publish();
|
||||
}
|
||||
this.publish();
|
||||
}
|
||||
checkIfClean() {
|
||||
for (const k in this.children) {
|
||||
|
|
@ -1785,7 +1805,7 @@ export class RunningTree<
|
|||
Cxt extends AsyncContext<ED>,
|
||||
FrontCxt extends SyncContext<ED>,
|
||||
AD extends CommonAspectDict<ED, Cxt>
|
||||
> extends Feature {
|
||||
> extends Feature {
|
||||
private cache: Cache<ED, Cxt, FrontCxt, AD>;
|
||||
private schema: StorageSchema<ED>;
|
||||
private root: Record<
|
||||
|
|
@ -2010,7 +2030,7 @@ export class RunningTree<
|
|||
this.cache.rollback();
|
||||
return value;
|
||||
}
|
||||
catch(err) {
|
||||
catch (err) {
|
||||
this.cache.rollback();
|
||||
throw err;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue