From 8e3a746c1239dd9611b477e7b20993645e1bd365 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Wed, 2 Nov 2022 12:42:52 +0800 Subject: [PATCH] =?UTF-8?q?runningTree=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/features/message.d.ts | 2 +- lib/features/message.js | 7 +++++- lib/features/runningTree.d.ts | 4 ++-- lib/features/runningTree.js | 41 +++++++++++++++++++++++++---------- lib/page.common.js | 16 ++++++++------ lib/page.web.js | 2 +- lib/types/Feature.js | 26 +++++++++++++--------- lib/types/Page.d.ts | 2 +- src/features/runningTree.ts | 6 ++--- 9 files changed, 68 insertions(+), 38 deletions(-) diff --git a/lib/features/message.d.ts b/lib/features/message.d.ts index 20ca5607..1d426c85 100644 --- a/lib/features/message.d.ts +++ b/lib/features/message.d.ts @@ -2,6 +2,6 @@ import { Feature } from '../types/Feature'; import { MessageProps } from '../types/Message'; export declare class Message extends Feature { private data?; - setMessage(data: MessageProps): void; + setMessage(data: MessageProps): Promise; consumeMessage(): MessageProps | undefined; } diff --git a/lib/features/message.js b/lib/features/message.js index 3af6439c..97bf2cb5 100644 --- a/lib/features/message.js +++ b/lib/features/message.js @@ -9,7 +9,12 @@ var Message = /** @class */ (function (_super) { return _super !== null && _super.apply(this, arguments) || this; } 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 () { var data = this.data; diff --git a/lib/features/runningTree.d.ts b/lib/features/runningTree.d.ts index e38e7e4f..adb76170 100644 --- a/lib/features/runningTree.d.ts +++ b/lib/features/runningTree.d.ts @@ -178,7 +178,7 @@ export declare class RunningTree; getPagination(path: string): Pagination; setId(path: string, id: string): Promise; - unsetId(path: string): void; + unsetId(path: string): Promise; getId(path: string): string | undefined; setPageSize(path: string, pageSize: number): Promise; setCurrentPage(path: string, currentPage: number): Promise; @@ -201,7 +201,7 @@ export declare class RunningTree; - clean(path: string): void; + clean(path: string): Promise; getRoot(): Record | ListNode>; } export {}; diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index 454e3eaa..cdef6572 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -2410,14 +2410,25 @@ var RunningTree = /** @class */ (function (_super) { return node.getPagination(); }; RunningTree.prototype.setId = function (path, id) { - var node = this.findNode(path); - (0, assert_1.assert)(node instanceof SingleNode); - return node.setId(id); + return tslib_1.__awaiter(this, void 0, void 0, function () { + var node; + 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) { - var node = this.findNode(path); - (0, assert_1.assert)(node instanceof SingleNode); - node.unsetId(); + return tslib_1.__awaiter(this, void 0, void 0, function () { + var node; + 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) { var node = this.findNode(path); @@ -2636,12 +2647,18 @@ var RunningTree = /** @class */ (function (_super) { }); }; RunningTree.prototype.clean = function (path) { - var node = this.findNode(path); - node.clean(); - var parent = node.getParent(); - if (parent) { - parent.checkIfClean(); - } + return tslib_1.__awaiter(this, void 0, void 0, function () { + var node, parent; + return tslib_1.__generator(this, function (_a) { + node = this.findNode(path); + node.clean(); + parent = node.getParent(); + if (parent) { + parent.checkIfClean(); + } + return [2 /*return*/]; + }); + }); }; RunningTree.prototype.getRoot = function () { return this.root; diff --git a/lib/page.common.js b/lib/page.common.js index f352ba9c..11e13453 100644 --- a/lib/page.common.js +++ b/lib/page.common.js @@ -354,19 +354,21 @@ function execute(operation, path) { } _a.label = 1; case 1: - _a.trys.push([1, 3, , 4]); + _a.trys.push([1, 4, , 5]); fullpath = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; return [4 /*yield*/, this.features.runningTree.execute(fullpath, operation)]; case 2: result = _a.sent(); - this.setMessage({ - type: 'success', - content: '操作成功', - }); - return [2 /*return*/, result]; + return [4 /*yield*/, this.setMessage({ + type: 'success', + content: '操作成功', + })]; case 3: + _a.sent(); + return [2 /*return*/, result]; + case 4: err_4 = _a.sent(); if (err_4 instanceof types_1.OakUserException) { if (err_4 instanceof types_1.OakInputIllegalException) { @@ -386,7 +388,7 @@ function execute(operation, path) { content: err_4.message, }); throw err_4; - case 4: return [2 /*return*/]; + case 5: return [2 /*return*/]; } }); }); diff --git a/lib/page.web.js b/lib/page.web.js index 62ec2ace..1f22ba54 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -71,7 +71,7 @@ var OakComponentBase = /** @class */ (function (_super) { return this.features.notification.consumeNotification(); }; OakComponentBase.prototype.setMessage = function (data) { - this.features.message.setMessage(data); + return this.features.message.setMessage(data); }; OakComponentBase.prototype.consumeMessage = function () { return this.features.message.consumeMessage(); diff --git a/lib/types/Feature.js b/lib/types/Feature.js index 0fd4cb19..563d7ffa 100644 --- a/lib/types/Feature.js +++ b/lib/types/Feature.js @@ -38,31 +38,37 @@ function Action(target, propertyName, descriptor) { switch (_a.label) { case 0: 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")); } _a.label = 1; case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, method.apply(this, params)]; + _a.trys.push([1, 5, , 6]); + result = method.apply(this, params); + if (!(result instanceof Promise)) return [3 /*break*/, 3]; + return [4 /*yield*/, result]; case 2: - result = _a.sent(); + _a.sent(); return [3 /*break*/, 4]; 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(); // console.error(err, method.name); mActionStackDepth--; throw err_1; - case 4: + case 6: 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; }); - if (!(results.length > 0)) return [3 /*break*/, 6]; + if (!(results.length > 0)) return [3 /*break*/, 8]; return [4 /*yield*/, Promise.all(results)]; - case 5: + case 7: _a.sent(); - _a.label = 6; - case 6: return [2 /*return*/, result]; + _a.label = 8; + case 8: return [2 /*return*/, result]; } }); }); diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index a795ae01..8093a6c4 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -134,7 +134,7 @@ export declare type OakCommonComponentMethods void; consumeNotification: () => NotificationProps | undefined; - setMessage: (data: MessageProps) => void; + setMessage: (data: MessageProps) => Promise; consumeMessage: () => MessageProps | undefined; reRender: (extra?: Record) => Promise; getFreshValue: (path?: string) => Promise; diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index ba6549d8..890e15cf 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -1859,14 +1859,14 @@ export class RunningTree< } @Action - setId(path: string, id: string) { + async setId(path: string, id: string) { const node = this.findNode(path); assert(node instanceof SingleNode); return node.setId(id); } @Action - unsetId(path: string) { + async unsetId(path: string) { const node = this.findNode(path); assert(node instanceof SingleNode); node.unsetId(); @@ -2067,7 +2067,7 @@ export class RunningTree< } @Action - clean(path: string) { + async clean(path: string) { const node = this.findNode(path)!; node.clean();