mm_effect 0.0.0-stage → 1.0.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/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # 副作用(mm_effect)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## 说明
4
+
5
+ mm_effect 是副作用管理模块,提供副作用的注册与管理能力。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install mm_effect
11
+ ```
12
+
13
+ ## 状态
14
+
15
+ 模块骨架已创建,功能开发中。
package/index.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const Effect = require('./lib/effect');
4
+
5
+ /**
6
+ * 作用域实例表
7
+ * @type {Map<string, Effect>}
8
+ */
9
+ const effects = new Map();
10
+
11
+ /**
12
+ * 获取指定作用域的副作用管理器实例,不存在时创建
13
+ * @param {string} [scope] 作用域名称,缺省时使用 os
14
+ * @param {Object} [config] 副作用配置项
15
+ * @returns {Effect} 副作用实例
16
+ */
17
+ function effectAdmin(scope, config) {
18
+ if (!scope) {
19
+ scope = 'os';
20
+ }
21
+ let effect = effects.get(scope);
22
+ if (!effect) {
23
+ effect = new Effect(config);
24
+ effects.set(scope, effect);
25
+ }
26
+ return effect;
27
+ }
28
+
29
+ module.exports = {
30
+ Effect,
31
+ effectAdmin
32
+ };
package/lib/effect.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Effect —— 副作用管理模块。
5
+ *
6
+ * 骨架已就绪:构造时接收配置对象,具体功能待开发。
7
+ */
8
+ class Effect {
9
+ /**
10
+ * 构造函数
11
+ * @param {Object} [config] 模块配置
12
+ */
13
+ constructor(config = {}) {
14
+ this.config = config;
15
+ }
16
+ }
17
+
18
+ module.exports = Effect;
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
- "name": "mm_effect",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "mm_effect",
3
+ "version": "1.0.1",
4
+ "description": "副作用管理模块:提供副作用的注册与管理能力",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://gitee.com/qiuwenwu91/mm_effect.git"
9
+ },
10
+ "keywords": [
11
+ "mm_mod",
12
+ "mm_infra",
13
+ "side_effect",
14
+ "副作用"
15
+ ],
16
+ "layer": "infra",
17
+ "group": "common",
18
+ "author": "邱文武",
19
+ "license": "ISC",
20
+ "engines": {
21
+ "node": ">=18.0.0"
22
+ },
23
+ "scripts": {
24
+ "test": "node test.js"
25
+ }
26
+ }
package/test.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const mod = require('./index.js');
5
+
6
+ // 1. 导出结构校验
7
+ assert.strictEqual(typeof mod.Effect, 'function', '应导出 Effect 类');
8
+ assert.strictEqual(typeof mod.effectAdmin, 'function', '应导出 effectAdmin 函数');
9
+
10
+ const { Effect } = mod;
11
+
12
+ // 2. 实例化与默认配置
13
+ const instance = new Effect();
14
+ assert.ok(instance instanceof Effect, 'instance 应为 Effect 实例');
15
+ assert.deepStrictEqual(instance.config, {}, '默认配置应为空对象');
16
+
17
+ // 3. 传入配置
18
+ const configured = new Effect({ async: true });
19
+ assert.deepStrictEqual(configured.config, { async: true }, '应保存传入的配置');
20
+
21
+ // 4. 工厂函数:同作用域返回同一实例
22
+ const scoped = mod.effectAdmin('test');
23
+ assert.ok(scoped instanceof Effect, 'effectAdmin 应返回 Effect 实例');
24
+ assert.strictEqual(mod.effectAdmin('test'), scoped, '同作用域应返回同一实例');
25
+
26
+ // 5. 缺省作用域为 os
27
+ assert.ok(mod.effectAdmin() instanceof Effect, '缺省作用域应返回 Effect 实例');
28
+ assert.strictEqual(mod.effectAdmin(), mod.effectAdmin('os'), '缺省作用域应与 os 一致');
29
+
30
+ console.log('mm_effect test passed');