mm_expand 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/eventer.js +11 -10
  2. package/package.json +1 -1
package/lib/eventer.js CHANGED
@@ -628,7 +628,7 @@ Eventer.prototype._execSingleTask = async function (o, params, ctx, options) {
628
628
  this._handleSuccessResult({ result, o, ctx, arr, task });
629
629
  } catch (e) {
630
630
  // 处理错误
631
- this._handleTaskError(e, o, ctx, task);
631
+ this._handleSeqTaskError(e, o, ctx, task);
632
632
  }
633
633
  };
634
634
 
@@ -667,7 +667,7 @@ Eventer.prototype._handleSuccessResult = function (config) {
667
667
  task.tasks.splice(task.tasks.indexOf(task.task), 1);
668
668
  };
669
669
 
670
- Eventer.prototype._handleTaskError = function (e, o, ctx, task) {
670
+ Eventer.prototype._handleSeqTaskError = function (e, o, ctx, task) {
671
671
  ctx.error_count++;
672
672
  this.log('error', `事件执行失败 [${ctx.space}:${ctx.event}] - ${o.name}`, e);
673
673
 
@@ -1265,7 +1265,7 @@ Eventer.prototype._ensureNs = function (name) {
1265
1265
  */
1266
1266
  Eventer.prototype._execNsEvents = async function (name, key, params) {
1267
1267
  let list = this._dict[name][key];
1268
- const space_results = [];
1268
+ const name_results = [];
1269
1269
  const arr = []; // 存储需要移除的事件
1270
1270
 
1271
1271
  // 执行事件处理函数
@@ -1274,7 +1274,7 @@ Eventer.prototype._execNsEvents = async function (name, key, params) {
1274
1274
  let obj = list[i];
1275
1275
  // 执行事件处理函数
1276
1276
  let result = await obj.func.apply(obj, params);
1277
- space_results.push(result);
1277
+ name_results.push(result);
1278
1278
 
1279
1279
  // 处理执行次数限制
1280
1280
  if (obj.times >= 0) {
@@ -1286,7 +1286,7 @@ Eventer.prototype._execNsEvents = async function (name, key, params) {
1286
1286
  } catch (e) {
1287
1287
  // 记录错误但不中断执行
1288
1288
  this.log('error', `事件执行失败 [${name}:${key}] - ${list[i].name}`, e);
1289
- space_results.push({
1289
+ name_results.push({
1290
1290
  _error: true,
1291
1291
  error: e,
1292
1292
  handler: list[i].name
@@ -1687,7 +1687,7 @@ Eventer.prototype._addTargetEvents = function (full_from_event, to_events) {
1687
1687
  let target_events = Array.isArray(to_events) ? to_events : [to_events];
1688
1688
 
1689
1689
  for (let i = 0; i < target_events.length; i++) {
1690
- this._addSingleTargetEvent(full_from_event, target_events[i]);
1690
+ this._addTargetEvent(full_from_event, target_events[i]);
1691
1691
  }
1692
1692
  };
1693
1693
 
@@ -1981,7 +1981,7 @@ Eventer.prototype.onMany = function (events_map) {
1981
1981
  }
1982
1982
 
1983
1983
  for (let event_name in events_map) {
1984
- if (events_map.has_own_property(event_name)) {
1984
+ if (Object.prototype.hasOwnProperty.call(events_map, event_name)) {
1985
1985
  this.on(event_name, events_map[event_name]);
1986
1986
  }
1987
1987
  }
@@ -2035,10 +2035,11 @@ Eventer.prototype._sort = function (events) {
2035
2035
  * @private
2036
2036
  */
2037
2037
  Eventer.prototype._runMiddleware = async function (type, ctx) {
2038
- if (!this._middleware || this._middleware.length === 0) return;
2038
+ if (!this._middleware || !this._middleware[type] || this._middleware[type].length === 0) return;
2039
2039
 
2040
- for (let i = 0; i < this._middleware.length; i++) {
2041
- await this._executeSingleMiddleware(this._middleware[i], type, ctx, i);
2040
+ const mwList = this._middleware[type];
2041
+ for (let i = 0; i < mwList.length; i++) {
2042
+ await this._execMiddleware(mwList[i], type, ctx, i);
2042
2043
  // 如果上下文被取消,则停止执行
2043
2044
  if (ctx.cancelled) break;
2044
2045
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "超级美眉原型函数扩展模块 - 增强的字符串、数组、对象、日期操作,具备错误预防功能并简化业务逻辑",
5
5
  "main": "index.js",
6
6
  "scripts": {