runningTree的小问题

This commit is contained in:
Xu Chang 2022-11-02 12:42:52 +08:00
parent 23ab185ad2
commit 8e3a746c12
9 changed files with 68 additions and 38 deletions

View File

@ -2,6 +2,6 @@ import { Feature } from '../types/Feature';
import { MessageProps } from '../types/Message'; import { MessageProps } from '../types/Message';
export declare class Message extends Feature { export declare class Message extends Feature {
private data?; private data?;
setMessage(data: MessageProps): void; setMessage(data: MessageProps): Promise<void>;
consumeMessage(): MessageProps | undefined; consumeMessage(): MessageProps | undefined;
} }

View File

@ -9,7 +9,12 @@ var Message = /** @class */ (function (_super) {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
Message.prototype.setMessage = function (data) { Message.prototype.setMessage = function (data) {
this.data = data; return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
this.data = data;
return [2 /*return*/];
});
});
}; };
Message.prototype.consumeMessage = function () { Message.prototype.consumeMessage = function () {
var data = this.data; var data = this.data;

View File

@ -178,7 +178,7 @@ export declare class RunningTree<ED extends EntityDict & BaseEntityDict, Cxt ext
loadMore(path: string): Promise<void>; loadMore(path: string): Promise<void>;
getPagination<T extends keyof ED>(path: string): Pagination; getPagination<T extends keyof ED>(path: string): Pagination;
setId(path: string, id: string): Promise<void>; setId(path: string, id: string): Promise<void>;
unsetId(path: string): void; unsetId(path: string): Promise<void>;
getId(path: string): string | undefined; getId(path: string): string | undefined;
setPageSize<T extends keyof ED>(path: string, pageSize: number): Promise<void>; setPageSize<T extends keyof ED>(path: string, pageSize: number): Promise<void>;
setCurrentPage<T extends keyof ED>(path: string, currentPage: number): Promise<void>; setCurrentPage<T extends keyof ED>(path: string, currentPage: number): Promise<void>;
@ -201,7 +201,7 @@ export declare class RunningTree<ED extends EntityDict & BaseEntityDict, Cxt ext
execute(path: string, operation?: ED[keyof ED]['Operation']): Promise<any[] | (ED[keyof ED]["Operation"] & { execute(path: string, operation?: ED[keyof ED]['Operation']): Promise<any[] | (ED[keyof ED]["Operation"] & {
entity: keyof ED; entity: keyof ED;
})[]>; })[]>;
clean(path: string): void; clean(path: string): Promise<void>;
getRoot(): Record<string, VirtualNode | SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>>; getRoot(): Record<string, VirtualNode | SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>>;
} }
export {}; export {};

View File

@ -2410,14 +2410,25 @@ var RunningTree = /** @class */ (function (_super) {
return node.getPagination(); return node.getPagination();
}; };
RunningTree.prototype.setId = function (path, id) { RunningTree.prototype.setId = function (path, id) {
var node = this.findNode(path); return tslib_1.__awaiter(this, void 0, void 0, function () {
(0, assert_1.assert)(node instanceof SingleNode); var node;
return node.setId(id); return tslib_1.__generator(this, function (_a) {
node = this.findNode(path);
(0, assert_1.assert)(node instanceof SingleNode);
return [2 /*return*/, node.setId(id)];
});
});
}; };
RunningTree.prototype.unsetId = function (path) { RunningTree.prototype.unsetId = function (path) {
var node = this.findNode(path); return tslib_1.__awaiter(this, void 0, void 0, function () {
(0, assert_1.assert)(node instanceof SingleNode); var node;
node.unsetId(); return tslib_1.__generator(this, function (_a) {
node = this.findNode(path);
(0, assert_1.assert)(node instanceof SingleNode);
node.unsetId();
return [2 /*return*/];
});
});
}; };
RunningTree.prototype.getId = function (path) { RunningTree.prototype.getId = function (path) {
var node = this.findNode(path); var node = this.findNode(path);
@ -2636,12 +2647,18 @@ var RunningTree = /** @class */ (function (_super) {
}); });
}; };
RunningTree.prototype.clean = function (path) { RunningTree.prototype.clean = function (path) {
var node = this.findNode(path); return tslib_1.__awaiter(this, void 0, void 0, function () {
node.clean(); var node, parent;
var parent = node.getParent(); return tslib_1.__generator(this, function (_a) {
if (parent) { node = this.findNode(path);
parent.checkIfClean(); node.clean();
} parent = node.getParent();
if (parent) {
parent.checkIfClean();
}
return [2 /*return*/];
});
});
}; };
RunningTree.prototype.getRoot = function () { RunningTree.prototype.getRoot = function () {
return this.root; return this.root;

View File

@ -354,19 +354,21 @@ function execute(operation, path) {
} }
_a.label = 1; _a.label = 1;
case 1: case 1:
_a.trys.push([1, 3, , 4]); _a.trys.push([1, 4, , 5]);
fullpath = path fullpath = path
? "".concat(this.state.oakFullpath, ".").concat(path) ? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath; : this.state.oakFullpath;
return [4 /*yield*/, this.features.runningTree.execute(fullpath, operation)]; return [4 /*yield*/, this.features.runningTree.execute(fullpath, operation)];
case 2: case 2:
result = _a.sent(); result = _a.sent();
this.setMessage({ return [4 /*yield*/, this.setMessage({
type: 'success', type: 'success',
content: '操作成功', content: '操作成功',
}); })];
return [2 /*return*/, result];
case 3: case 3:
_a.sent();
return [2 /*return*/, result];
case 4:
err_4 = _a.sent(); err_4 = _a.sent();
if (err_4 instanceof types_1.OakUserException) { if (err_4 instanceof types_1.OakUserException) {
if (err_4 instanceof types_1.OakInputIllegalException) { if (err_4 instanceof types_1.OakInputIllegalException) {
@ -386,7 +388,7 @@ function execute(operation, path) {
content: err_4.message, content: err_4.message,
}); });
throw err_4; throw err_4;
case 4: return [2 /*return*/]; case 5: return [2 /*return*/];
} }
}); });
}); });

View File

@ -71,7 +71,7 @@ var OakComponentBase = /** @class */ (function (_super) {
return this.features.notification.consumeNotification(); return this.features.notification.consumeNotification();
}; };
OakComponentBase.prototype.setMessage = function (data) { OakComponentBase.prototype.setMessage = function (data) {
this.features.message.setMessage(data); return this.features.message.setMessage(data);
}; };
OakComponentBase.prototype.consumeMessage = function () { OakComponentBase.prototype.consumeMessage = function () {
return this.features.message.consumeMessage(); return this.features.message.consumeMessage();

View File

@ -38,31 +38,37 @@ function Action(target, propertyName, descriptor) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
mActionStackDepth++; mActionStackDepth++;
if (mActionStackDepth > 20) { if (mActionStackDepth > 1000) {
console.error("action[".concat(method.name, "]\u8C03\u7528\u7684\u5C42\u7EA7\u8D85\u8FC7\u4E8620\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u5B58\u5728\u65E0\u9650\u9012\u5F52")); console.error("action[".concat(method.name, "]\u8C03\u7528\u7684\u5C42\u7EA7\u8D85\u8FC7\u4E8620\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u5B58\u5728\u65E0\u9650\u9012\u5F52"));
} }
_a.label = 1; _a.label = 1;
case 1: case 1:
_a.trys.push([1, 3, , 4]); _a.trys.push([1, 5, , 6]);
return [4 /*yield*/, method.apply(this, params)]; result = method.apply(this, params);
if (!(result instanceof Promise)) return [3 /*break*/, 3];
return [4 /*yield*/, result];
case 2: case 2:
result = _a.sent(); _a.sent();
return [3 /*break*/, 4]; return [3 /*break*/, 4];
case 3: case 3:
console.error("\u65B9\u6CD5".concat(method.name, "\u88AB\u5B9A\u4E49\u4E3Aaction\u4F46\u4E0D\u662F\u5F02\u6B65\u51FD\u6570\uFF0C\u53EF\u80FD\u4F1A\u5F15\u8D77\u5BF9\u8C61\u89E3\u6784\u548C\u91CD\u6E32\u67D3\u4E4B\u95F4\u7684\u4E0D\u6B63\u786E\u540C\u6B65"));
_a.label = 4;
case 4: return [3 /*break*/, 6];
case 5:
err_1 = _a.sent(); err_1 = _a.sent();
// console.error(err, method.name); // console.error(err, method.name);
mActionStackDepth--; mActionStackDepth--;
throw err_1; throw err_1;
case 4: case 6:
mActionStackDepth--; mActionStackDepth--;
if (!(mActionStackDepth === 0)) return [3 /*break*/, 6]; if (!(mActionStackDepth === 0)) return [3 /*break*/, 8];
results = mCallbacks.map(function (ele) { return ele(); }).filter(function (ele) { return ele instanceof Promise; }); results = mCallbacks.map(function (ele) { return ele(); }).filter(function (ele) { return ele instanceof Promise; });
if (!(results.length > 0)) return [3 /*break*/, 6]; if (!(results.length > 0)) return [3 /*break*/, 8];
return [4 /*yield*/, Promise.all(results)]; return [4 /*yield*/, Promise.all(results)];
case 5: case 7:
_a.sent(); _a.sent();
_a.label = 6; _a.label = 8;
case 6: return [2 /*return*/, result]; case 8: return [2 /*return*/, result];
} }
}); });
}); });

2
lib/types/Page.d.ts vendored
View File

@ -134,7 +134,7 @@ export declare type OakCommonComponentMethods<ED extends EntityDict & BaseEntity
}; };
setNotification: (data: NotificationProps) => void; setNotification: (data: NotificationProps) => void;
consumeNotification: () => NotificationProps | undefined; consumeNotification: () => NotificationProps | undefined;
setMessage: (data: MessageProps) => void; setMessage: (data: MessageProps) => Promise<void>;
consumeMessage: () => MessageProps | undefined; consumeMessage: () => MessageProps | undefined;
reRender: (extra?: Record<string, any>) => Promise<void>; reRender: (extra?: Record<string, any>) => Promise<void>;
getFreshValue: (path?: string) => Promise<ED[keyof ED]['Schema'][] | ED[keyof ED]['Schema'] | undefined>; getFreshValue: (path?: string) => Promise<ED[keyof ED]['Schema'][] | ED[keyof ED]['Schema'] | undefined>;

View File

@ -1859,14 +1859,14 @@ export class RunningTree<
} }
@Action @Action
setId(path: string, id: string) { async setId(path: string, id: string) {
const node = this.findNode(path); const node = this.findNode(path);
assert(node instanceof SingleNode); assert(node instanceof SingleNode);
return node.setId(id); return node.setId(id);
} }
@Action @Action
unsetId(path: string) { async unsetId(path: string) {
const node = this.findNode(path); const node = this.findNode(path);
assert(node instanceof SingleNode); assert(node instanceof SingleNode);
node.unsetId(); node.unsetId();
@ -2067,7 +2067,7 @@ export class RunningTree<
} }
@Action @Action
clean(path: string) { async clean(path: string) {
const node = this.findNode(path)!; const node = this.findNode(path)!;
node.clean(); node.clean();