Skip to content

Commit

Permalink
fix 兼容 service eventlisteners 用法 review by luox
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Sep 5, 2023
1 parent a3803f9 commit 6af9667
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 177 deletions.
22 changes: 12 additions & 10 deletions src/common/iServer/CommonServiceBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class CommonServiceBase {
* @private
*/
serviceProcessCompleted(result, options) {
result = Util.transformResult(result);
result = this.transformResult(result).result;
this.events.triggerEvent('processCompleted', {
result: result,
options: options
Expand All @@ -269,7 +269,7 @@ export class CommonServiceBase {
* @private
*/
serviceProcessFailed(result, options) {
result = Util.transformResult(result);
result = this.transformErrorResult(result).error;
let error = result.error || result;
this.events.triggerEvent('processFailed', {
error: error,
Expand Down Expand Up @@ -360,23 +360,25 @@ export class CommonServiceBase {
object: this
};
if (requestResult.error) {
const type = 'processFailed';
// 兼容服务在构造函数中使用 eventListeners 的老用法
if (options.failure === this.serviceProcessFailed) {
var failure = options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure;
failure(requestResult, options);
if (this.events && this.events.listeners[type] && this.events.listeners[type].length) {
var failure = options.failure && (options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure);
failure ? failure(requestResult, options) : this.serviceProcessFailed(requestResult, options);
} else {
response = {...response, ...this.transformErrorResult(requestResult, options)};
response.type = 'processFailed';
response.type = type;
options.failure && options.failure(response);
}
} else {
if (options.success === this.serviceProcessCompleted) {
var success = options.scope ? FunctionExt.bind(options.success, options.scope) : options.success;
success(requestResult, options);
const type = 'processCompleted';
if (this.events && this.events.listeners[type] && this.events.listeners[type].length) {
var success = options.success && (options.scope ? FunctionExt.bind(options.success, options.scope) : options.success);
success ? success(requestResult, options) : this.serviceProcessCompleted(requestResult, options);
} else {
requestResult.succeed = requestResult.succeed == undefined ? true : requestResult.succeed;
response = {...response, ...this.transformResult(requestResult, options)};
response.type = 'processCompleted';
response.type = type;
options.success && options.success(response);
}
}
Expand Down
Loading

0 comments on commit 6af9667

Please sign in to comment.