mm_machine 2.5.0 → 2.5.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.
- package/drive.js +10 -5
- package/mod.js +10 -5
- package/package.json +1 -1
package/drive.js
CHANGED
|
@@ -361,12 +361,17 @@ Drive.prototype._setMainMethod = function (mod) {
|
|
|
361
361
|
if (name && mod[name]) {
|
|
362
362
|
this.main = mod[name];
|
|
363
363
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
364
|
+
|
|
365
|
+
for (let key in mod) {
|
|
366
|
+
let obj = mod[key];
|
|
367
|
+
if (typeof obj === 'function') {
|
|
368
|
+
this._methods[key] = obj;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
this._datas[key] = obj;
|
|
372
|
+
}
|
|
369
373
|
}
|
|
374
|
+
Object.assign(this, mod);
|
|
370
375
|
this.is_loaded = true;
|
|
371
376
|
};
|
|
372
377
|
|
package/mod.js
CHANGED
|
@@ -75,6 +75,10 @@ class Mod extends Base {
|
|
|
75
75
|
*/
|
|
76
76
|
constructor(config, parent = null) {
|
|
77
77
|
super(config);
|
|
78
|
+
// 脚本方法
|
|
79
|
+
this._methods = {};
|
|
80
|
+
// 脚本数据
|
|
81
|
+
this._datas = {};
|
|
78
82
|
// 是否已加载
|
|
79
83
|
this.is_loaded = false;
|
|
80
84
|
// 追加查询到上级的方法
|
|
@@ -326,8 +330,8 @@ Mod.prototype.unload = async function () {
|
|
|
326
330
|
* 卸载核心
|
|
327
331
|
*/
|
|
328
332
|
Mod.prototype._unloadCore = async function () {
|
|
329
|
-
if (this.
|
|
330
|
-
this.
|
|
333
|
+
if (this._methods) {
|
|
334
|
+
this._methods = {};
|
|
331
335
|
}
|
|
332
336
|
};
|
|
333
337
|
|
|
@@ -396,11 +400,12 @@ Mod.prototype.emitEvent = function (event, ...args) {
|
|
|
396
400
|
*/
|
|
397
401
|
Mod.prototype.main = async function (...args) {
|
|
398
402
|
let method = args[0];
|
|
399
|
-
|
|
403
|
+
let func = this.getMethod(method);
|
|
404
|
+
if (!func) {
|
|
400
405
|
throw new Error(`方法${method}不存在`);
|
|
401
406
|
}
|
|
402
407
|
let params = args.slice(1);
|
|
403
|
-
return await
|
|
408
|
+
return await func(...params);
|
|
404
409
|
};
|
|
405
410
|
|
|
406
411
|
/**
|
|
@@ -434,7 +439,7 @@ Mod.prototype.setMethod = function (method, func) {
|
|
|
434
439
|
* @returns {Function|null} 方法函数
|
|
435
440
|
*/
|
|
436
441
|
Mod.prototype.getMethod = function (method) {
|
|
437
|
-
let func = this._methods
|
|
442
|
+
let func = this._methods[method];
|
|
438
443
|
if (!func) {
|
|
439
444
|
func = this[method];
|
|
440
445
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|