@vlian/framework 1.2.63 → 2.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.
Files changed (185) hide show
  1. package/README.md +21 -141
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.ts +1 -9
  4. package/dist/index.js +1 -1
  5. package/dist/index.umd.js +10 -220
  6. package/dist/kernel/constants.cjs +1 -1
  7. package/dist/kernel/constants.d.ts +1 -3
  8. package/dist/kernel/constants.js +1 -1
  9. package/dist/kernel/custom-manager/i18n/constants.cjs +1 -0
  10. package/dist/kernel/custom-manager/i18n/constants.d.ts +4 -0
  11. package/dist/kernel/custom-manager/i18n/constants.js +1 -0
  12. package/dist/kernel/custom-manager/i18n/index.cjs +1 -0
  13. package/dist/kernel/custom-manager/i18n/index.d.ts +7 -0
  14. package/dist/kernel/custom-manager/i18n/index.js +1 -0
  15. package/dist/kernel/custom-manager/i18n/types.d.ts +10 -0
  16. package/dist/kernel/custom-manager/index.cjs +1 -0
  17. package/dist/kernel/custom-manager/index.d.ts +4 -0
  18. package/dist/kernel/custom-manager/index.js +1 -0
  19. package/dist/kernel/custom-manager/theme/constants.cjs +1 -0
  20. package/dist/kernel/custom-manager/theme/constants.d.ts +4 -0
  21. package/dist/kernel/custom-manager/theme/constants.js +1 -0
  22. package/dist/kernel/custom-manager/theme/index.cjs +1 -0
  23. package/dist/kernel/custom-manager/theme/index.d.ts +7 -0
  24. package/dist/kernel/custom-manager/theme/index.js +1 -0
  25. package/dist/kernel/custom-manager/theme/types.d.ts +14 -0
  26. package/dist/kernel/index.cjs +1 -1
  27. package/dist/kernel/index.d.ts +4 -2
  28. package/dist/kernel/index.js +1 -1
  29. package/dist/kernel/kernel.cjs +1 -1
  30. package/dist/kernel/kernel.d.ts +3 -7
  31. package/dist/kernel/kernel.js +1 -1
  32. package/dist/kernel/manager/i18n/I18nManager.cjs +1 -1
  33. package/dist/kernel/manager/i18n/I18nManager.d.ts +2 -1
  34. package/dist/kernel/manager/i18n/I18nManager.js +1 -1
  35. package/dist/kernel/manager/i18n/i18n.persistence.d.ts +2 -1
  36. package/dist/kernel/manager/i18n/i18n.runtime.cjs +1 -0
  37. package/dist/kernel/manager/i18n/i18n.runtime.d.ts +8 -0
  38. package/dist/kernel/manager/i18n/i18n.runtime.js +1 -0
  39. package/dist/kernel/manager/i18n/i18n.schema.d.ts +1 -1
  40. package/dist/kernel/manager/i18nManager.cjs +1 -1
  41. package/dist/kernel/manager/i18nManager.d.ts +1 -1
  42. package/dist/kernel/manager/i18nManager.js +1 -1
  43. package/dist/kernel/manager/index.cjs +1 -1
  44. package/dist/kernel/manager/index.d.ts +0 -2
  45. package/dist/kernel/manager/index.js +1 -1
  46. package/dist/kernel/manager/theme/ThemeManager.cjs +1 -1
  47. package/dist/kernel/manager/theme/ThemeManager.d.ts +8 -1
  48. package/dist/kernel/manager/theme/ThemeManager.js +1 -1
  49. package/dist/kernel/manager/theme/theme.dom.cjs +1 -1
  50. package/dist/kernel/manager/theme/theme.dom.d.ts +10 -3
  51. package/dist/kernel/manager/theme/theme.dom.js +1 -1
  52. package/dist/kernel/manager/theme/theme.persistence.d.ts +2 -1
  53. package/dist/kernel/manager/theme/theme.schema.cjs +1 -1
  54. package/dist/kernel/manager/theme/theme.schema.d.ts +3 -1
  55. package/dist/kernel/manager/theme/theme.schema.js +1 -1
  56. package/dist/kernel/manager/themeManager.cjs +1 -1
  57. package/dist/kernel/manager/themeManager.d.ts +1 -1
  58. package/dist/kernel/manager/themeManager.js +1 -1
  59. package/dist/kernel/types.d.ts +10 -39
  60. package/package.json +10 -133
  61. package/dist/analytics/index.cjs +0 -1
  62. package/dist/analytics/index.d.ts +0 -2
  63. package/dist/analytics/index.js +0 -1
  64. package/dist/analytics.umd.js +0 -19
  65. package/dist/components/index.cjs +0 -1
  66. package/dist/components/index.d.ts +0 -1
  67. package/dist/components/index.js +0 -1
  68. package/dist/components/persistence.cjs +0 -1
  69. package/dist/components/persistence.d.ts +0 -12
  70. package/dist/components/persistence.js +0 -1
  71. package/dist/library/index.cjs +0 -1
  72. package/dist/library/index.d.ts +0 -2
  73. package/dist/library/index.js +0 -1
  74. package/dist/library/locale/index.cjs +0 -1
  75. package/dist/library/locale/index.d.ts +0 -6
  76. package/dist/library/locale/index.js +0 -1
  77. package/dist/library/locale/langs/en-us/index.cjs +0 -1
  78. package/dist/library/locale/langs/en-us/index.d.ts +0 -3
  79. package/dist/library/locale/langs/en-us/index.js +0 -1
  80. package/dist/library/locale/langs/zh-cn/index.cjs +0 -1
  81. package/dist/library/locale/langs/zh-cn/index.d.ts +0 -3
  82. package/dist/library/locale/langs/zh-cn/index.js +0 -1
  83. package/dist/library/locale/types.d.ts +0 -38
  84. package/dist/library/storage/cache.cjs +0 -1
  85. package/dist/library/storage/cache.d.ts +0 -57
  86. package/dist/library/storage/cache.js +0 -1
  87. package/dist/library/storage/encryption.cjs +0 -1
  88. package/dist/library/storage/encryption.d.ts +0 -45
  89. package/dist/library/storage/encryption.js +0 -1
  90. package/dist/library/storage/index.cjs +0 -1
  91. package/dist/library/storage/index.d.ts +0 -62
  92. package/dist/library/storage/index.js +0 -1
  93. package/dist/state/StateManager.cjs +0 -1
  94. package/dist/state/StateManager.d.ts +0 -120
  95. package/dist/state/StateManager.js +0 -1
  96. package/dist/state/adapters/AdapterFactory.cjs +0 -1
  97. package/dist/state/adapters/AdapterFactory.d.ts +0 -51
  98. package/dist/state/adapters/AdapterFactory.js +0 -1
  99. package/dist/state/adapters/DefaultAdapter.cjs +0 -1
  100. package/dist/state/adapters/DefaultAdapter.d.ts +0 -38
  101. package/dist/state/adapters/DefaultAdapter.js +0 -1
  102. package/dist/state/adapters/ReduxAdapter.cjs +0 -1
  103. package/dist/state/adapters/ReduxAdapter.d.ts +0 -129
  104. package/dist/state/adapters/ReduxAdapter.js +0 -1
  105. package/dist/state/adapters/ZustandAdapter.cjs +0 -1
  106. package/dist/state/adapters/ZustandAdapter.d.ts +0 -46
  107. package/dist/state/adapters/ZustandAdapter.js +0 -1
  108. package/dist/state/adapters/index.cjs +0 -1
  109. package/dist/state/adapters/index.d.ts +0 -8
  110. package/dist/state/adapters/index.js +0 -1
  111. package/dist/state/adapters/types.cjs +0 -1
  112. package/dist/state/adapters/types.d.ts +0 -4
  113. package/dist/state/adapters/types.js +0 -1
  114. package/dist/state/core/DerivedStateInstance.cjs +0 -1
  115. package/dist/state/core/DerivedStateInstance.d.ts +0 -100
  116. package/dist/state/core/DerivedStateInstance.js +0 -1
  117. package/dist/state/core/StateInstance.cjs +0 -1
  118. package/dist/state/core/StateInstance.d.ts +0 -85
  119. package/dist/state/core/StateInstance.js +0 -1
  120. package/dist/state/core/StateRegistry.cjs +0 -1
  121. package/dist/state/core/StateRegistry.d.ts +0 -55
  122. package/dist/state/core/StateRegistry.js +0 -1
  123. package/dist/state/core/StateScope.cjs +0 -1
  124. package/dist/state/core/StateScope.d.ts +0 -71
  125. package/dist/state/core/StateScope.js +0 -1
  126. package/dist/state/core/index.cjs +0 -1
  127. package/dist/state/core/index.d.ts +0 -7
  128. package/dist/state/core/index.js +0 -1
  129. package/dist/state/index.cjs +0 -1
  130. package/dist/state/index.d.ts +0 -8
  131. package/dist/state/index.js +0 -1
  132. package/dist/state/types.d.ts +0 -230
  133. package/dist/state.umd.js +0 -41
  134. package/dist/types.cjs +0 -1
  135. package/dist/types.d.ts +0 -7
  136. package/dist/types.js +0 -1
  137. package/dist/utils/analytics.cjs +0 -1
  138. package/dist/utils/analytics.d.ts +0 -127
  139. package/dist/utils/analytics.js +0 -1
  140. package/dist/utils/configSecurity.cjs +0 -3
  141. package/dist/utils/configSecurity.d.ts +0 -100
  142. package/dist/utils/configSecurity.js +0 -3
  143. package/dist/utils/csrf.cjs +0 -1
  144. package/dist/utils/csrf.d.ts +0 -1
  145. package/dist/utils/csrf.js +0 -1
  146. package/dist/utils/errors/ErrorCodes.cjs +0 -1
  147. package/dist/utils/errors/ErrorCodes.d.ts +0 -1
  148. package/dist/utils/errors/ErrorCodes.js +0 -1
  149. package/dist/utils/errors.cjs +0 -1
  150. package/dist/utils/errors.d.ts +0 -30
  151. package/dist/utils/errors.js +0 -1
  152. package/dist/utils/index.cjs +0 -1
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -1
  155. package/dist/utils/logger.cjs +0 -1
  156. package/dist/utils/logger.d.ts +0 -2
  157. package/dist/utils/logger.js +0 -1
  158. package/dist/utils/logger.types.cjs +0 -1
  159. package/dist/utils/logger.types.d.ts +0 -2
  160. package/dist/utils/logger.types.js +0 -1
  161. package/dist/utils/monitoring.cjs +0 -1
  162. package/dist/utils/monitoring.d.ts +0 -1
  163. package/dist/utils/monitoring.js +0 -1
  164. package/dist/utils/performance.cjs +0 -1
  165. package/dist/utils/performance.d.ts +0 -2
  166. package/dist/utils/performance.js +0 -1
  167. package/dist/utils/resourceLoader.cjs +0 -1
  168. package/dist/utils/resourceLoader.d.ts +0 -2
  169. package/dist/utils/resourceLoader.js +0 -1
  170. package/dist/utils/runtimeSecurity.cjs +0 -1
  171. package/dist/utils/runtimeSecurity.d.ts +0 -2
  172. package/dist/utils/runtimeSecurity.js +0 -1
  173. package/dist/utils/security.cjs +0 -1
  174. package/dist/utils/security.d.ts +0 -2
  175. package/dist/utils/security.js +0 -1
  176. package/dist/utils/traceId.cjs +0 -1
  177. package/dist/utils/traceId.d.ts +0 -1
  178. package/dist/utils/traceId.js +0 -1
  179. package/dist/utils/validation.cjs +0 -1
  180. package/dist/utils/validation.d.ts +0 -2
  181. package/dist/utils/validation.js +0 -1
  182. /package/dist/{library/locale → kernel/custom-manager/i18n}/types.cjs +0 -0
  183. /package/dist/{library/locale → kernel/custom-manager/i18n}/types.js +0 -0
  184. /package/dist/{state → kernel/custom-manager/theme}/types.cjs +0 -0
  185. /package/dist/{state → kernel/custom-manager/theme}/types.js +0 -0
@@ -1,120 +0,0 @@
1
- /**
2
- * 状态管理器主类
3
- *
4
- * 这是状态管理器的核心入口,提供统一的状态管理 API
5
- */
6
- import type { IStateInstance, IStateAdapter, IStateRegistry, StateInstanceOptions, StateManagerOptions, StateScope, DerivedStateConfig, IDerivedStateInstance } from './types';
7
- /**
8
- * 状态管理器实现
9
- */
10
- export declare class StateManager implements IStateManager {
11
- /**
12
- * 默认适配器
13
- */
14
- private readonly adapter;
15
- /**
16
- * 状态注册表(如果启用)
17
- */
18
- private readonly registry;
19
- /**
20
- * 默认作用域
21
- */
22
- private readonly defaultScope?;
23
- /**
24
- * 是否启用开发模式
25
- */
26
- private readonly devMode;
27
- /**
28
- * 是否已销毁
29
- */
30
- private destroyed;
31
- /**
32
- * 构造函数
33
- *
34
- * @param options - 状态管理器配置选项
35
- */
36
- constructor(options?: StateManagerOptions);
37
- /**
38
- * 创建状态实例
39
- */
40
- createState<T = unknown>(initialValue: T, options?: StateInstanceOptions): IStateInstance<T>;
41
- /**
42
- * 创建派生状态
43
- */
44
- createDerivedState<T, D extends readonly IStateInstance[]>(config: DerivedStateConfig<T, D>, options?: {
45
- id?: string | symbol;
46
- scope?: StateScope;
47
- }): IDerivedStateInstance<T>;
48
- /**
49
- * 获取状态实例(如果启用了注册表)
50
- */
51
- getState(id: string | symbol): IStateInstance | undefined;
52
- /**
53
- * 根据作用域获取所有状态实例
54
- */
55
- getStatesByScope(scope: StateScope): IStateInstance[];
56
- /**
57
- * 获取所有状态实例
58
- */
59
- getAllStates(): IStateInstance[];
60
- /**
61
- * 销毁指定作用域的所有状态实例
62
- */
63
- destroyScope(scope: StateScope): void;
64
- /**
65
- * 销毁状态管理器
66
- */
67
- destroy(): void;
68
- /**
69
- * 检查状态管理器是否已销毁
70
- */
71
- isDestroyed(): boolean;
72
- /**
73
- * 获取当前使用的适配器
74
- */
75
- getAdapter(): IStateAdapter;
76
- /**
77
- * 获取注册表(如果启用)
78
- */
79
- getRegistry(): IStateRegistry | null;
80
- }
81
- /**
82
- * 状态管理器接口
83
- */
84
- export interface IStateManager {
85
- /**
86
- * 创建状态实例
87
- */
88
- createState<T = unknown>(initialValue: T, options?: StateInstanceOptions): IStateInstance<T>;
89
- /**
90
- * 创建派生状态
91
- */
92
- createDerivedState<T, D extends readonly IStateInstance[]>(config: DerivedStateConfig<T, D>, options?: {
93
- id?: string | symbol;
94
- scope?: StateScope;
95
- }): IDerivedStateInstance<T>;
96
- /**
97
- * 获取状态实例
98
- */
99
- getState(id: string | symbol): IStateInstance | undefined;
100
- /**
101
- * 根据作用域获取所有状态实例
102
- */
103
- getStatesByScope(scope: StateScope): IStateInstance[];
104
- /**
105
- * 获取所有状态实例
106
- */
107
- getAllStates(): IStateInstance[];
108
- /**
109
- * 销毁指定作用域的所有状态实例
110
- */
111
- destroyScope(scope: StateScope): void;
112
- /**
113
- * 销毁状态管理器
114
- */
115
- destroy(): void;
116
- /**
117
- * 检查状态管理器是否已销毁
118
- */
119
- isDestroyed(): boolean;
120
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{AdapterFactory}from"./adapters/AdapterFactory";import{StateRegistry}from"./core/StateRegistry";import{DerivedStateInstance}from"./core/DerivedStateInstance";export class StateManager{createState(initialValue,options){if(this.destroyed){throw new Error("StateManager has been destroyed")}const mergedOptions={...options,scope:options?.scope??this.defaultScope,devMode:options?.devMode??this.devMode};const instance=this.adapter.createInstance(initialValue,mergedOptions);if(this.registry){this.registry.register(instance)}return instance}createDerivedState(config,options){if(this.destroyed){throw new Error("StateManager has been destroyed")}const mergedOptions={...options,scope:options?.scope??this.defaultScope};const instance=new DerivedStateInstance(config,mergedOptions);if(this.registry){this.registry.register(instance)}return instance}getState(id){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getInstance(id)}getStatesByScope(scope){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getInstancesByScope(scope)}getAllStates(){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}return this.registry.getAllInstances()}destroyScope(scope){if(!this.registry){throw new Error("Registry is not enabled. Enable it in StateManagerOptions.")}this.registry.destroyScope(scope)}destroy(){if(this.destroyed){return}this.destroyed=true;if(this.registry){this.registry.destroyAll()}this.adapter.destroy();if(this.devMode){console.debug("[StateManager] Destroyed")}}isDestroyed(){return this.destroyed}getAdapter(){return this.adapter}getRegistry(){return this.registry}constructor(options={}){_define_property(this,"adapter",void 0);_define_property(this,"registry",void 0);_define_property(this,"defaultScope",void 0);_define_property(this,"devMode",void 0);_define_property(this,"destroyed",false);this.adapter=options.defaultAdapter??AdapterFactory.getDefaultAdapter();this.defaultScope=options.defaultScope;this.devMode=options.devMode??false;this.registry=options.enableRegistry!==false?new StateRegistry:null;if(this.devMode){console.debug("[StateManager] Initialized",{adapter:this.adapter.getName(),registryEnabled:!!this.registry,defaultScope:this.defaultScope})}}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"AdapterFactory",{enumerable:true,get:function(){return AdapterFactory}});const _DefaultAdapter=require("./DefaultAdapter");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let AdapterFactory=class AdapterFactory{static getDefaultAdapter(){if(!this.defaultAdapter){this.defaultAdapter=new _DefaultAdapter.DefaultAdapter}return this.defaultAdapter}static createAdapter(adapterName){if(!adapterName){return this.getDefaultAdapter()}const factory=this.customAdapters.get(adapterName);if(!factory){throw new Error(`Adapter "${adapterName}" not found. Available adapters: ${Array.from(this.customAdapters.keys()).join(", ")}`)}return factory()}static registerAdapter(name,factory){if(this.customAdapters.has(name)){console.warn(`[AdapterFactory] Adapter "${name}" already registered, replacing...`)}this.customAdapters.set(name,factory)}static unregisterAdapter(name){this.customAdapters.delete(name)}static getRegisteredAdapters(){return Array.from(this.customAdapters.keys())}static reset(){if(this.defaultAdapter){this.defaultAdapter.destroy();this.defaultAdapter=null}this.customAdapters.clear()}};_define_property(AdapterFactory,"defaultAdapter",null);_define_property(AdapterFactory,"customAdapters",new Map);
@@ -1,51 +0,0 @@
1
- /**
2
- * 状态适配器工厂
3
- */
4
- import type { IStateAdapter } from '../types';
5
- /**
6
- * 适配器工厂
7
- *
8
- * 负责创建和管理状态适配器实例
9
- */
10
- export declare class AdapterFactory {
11
- /**
12
- * 默认适配器实例
13
- */
14
- private static defaultAdapter;
15
- /**
16
- * 自定义适配器映射
17
- */
18
- private static customAdapters;
19
- /**
20
- * 获取默认适配器
21
- */
22
- static getDefaultAdapter(): IStateAdapter;
23
- /**
24
- * 创建适配器实例
25
- *
26
- * @param adapterName - 适配器名称,如果不提供则使用默认适配器
27
- * @returns 适配器实例
28
- */
29
- static createAdapter(adapterName?: string): IStateAdapter;
30
- /**
31
- * 注册自定义适配器
32
- *
33
- * @param name - 适配器名称
34
- * @param factory - 适配器工厂函数
35
- */
36
- static registerAdapter(name: string, factory: () => IStateAdapter): void;
37
- /**
38
- * 注销适配器
39
- *
40
- * @param name - 适配器名称
41
- */
42
- static unregisterAdapter(name: string): void;
43
- /**
44
- * 获取所有已注册的适配器名称
45
- */
46
- static getRegisteredAdapters(): string[];
47
- /**
48
- * 重置工厂(主要用于测试)
49
- */
50
- static reset(): void;
51
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{DefaultAdapter}from"./DefaultAdapter";export class AdapterFactory{static getDefaultAdapter(){if(!this.defaultAdapter){this.defaultAdapter=new DefaultAdapter}return this.defaultAdapter}static createAdapter(adapterName){if(!adapterName){return this.getDefaultAdapter()}const factory=this.customAdapters.get(adapterName);if(!factory){throw new Error(`Adapter "${adapterName}" not found. Available adapters: ${Array.from(this.customAdapters.keys()).join(", ")}`)}return factory()}static registerAdapter(name,factory){if(this.customAdapters.has(name)){console.warn(`[AdapterFactory] Adapter "${name}" already registered, replacing...`)}this.customAdapters.set(name,factory)}static unregisterAdapter(name){this.customAdapters.delete(name)}static getRegisteredAdapters(){return Array.from(this.customAdapters.keys())}static reset(){if(this.defaultAdapter){this.defaultAdapter.destroy();this.defaultAdapter=null}this.customAdapters.clear()}}_define_property(AdapterFactory,"defaultAdapter",null);_define_property(AdapterFactory,"customAdapters",new Map);
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DefaultAdapter",{enumerable:true,get:function(){return DefaultAdapter}});const _StateInstance=require("../core/StateInstance");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let DefaultAdapter=class DefaultAdapter{createInstance(initialValue,options){if(this.destroyed){throw new Error("Adapter has been destroyed")}const instance=new _StateInstance.StateInstance(initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode,middleware:options?.middleware});this.instances.add(instance);return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}this.instances.clear();this.destroyed=true}getName(){return this.name}constructor(){_define_property(this,"name","DefaultAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set)}};
@@ -1,38 +0,0 @@
1
- /**
2
- * 默认状态适配器
3
- *
4
- * 这是 Secra Framework 内置的默认状态适配器实现
5
- * 不依赖任何外部状态管理库,提供基础的状态管理能力
6
- */
7
- import type { IStateAdapter, IStateInstance, StateInstanceOptions } from '../types';
8
- /**
9
- * 默认状态适配器
10
- *
11
- * 使用框架内置的 StateInstance 实现
12
- */
13
- export declare class DefaultAdapter implements IStateAdapter {
14
- /**
15
- * 适配器名称
16
- */
17
- private readonly name;
18
- /**
19
- * 是否已销毁
20
- */
21
- private destroyed;
22
- /**
23
- * 创建的状态实例集合(用于销毁时清理)
24
- */
25
- private readonly instances;
26
- /**
27
- * 创建状态实例
28
- */
29
- createInstance<T>(initialValue: T, options?: StateInstanceOptions): IStateInstance<T>;
30
- /**
31
- * 销毁适配器
32
- */
33
- destroy(): void;
34
- /**
35
- * 获取适配器名称
36
- */
37
- getName(): string;
38
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}import{StateInstance}from"../core/StateInstance";export class DefaultAdapter{createInstance(initialValue,options){if(this.destroyed){throw new Error("Adapter has been destroyed")}const instance=new StateInstance(initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode,middleware:options?.middleware});this.instances.add(instance);return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}this.instances.clear();this.destroyed=true}getName(){return this.name}constructor(){_define_property(this,"name","DefaultAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set)}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"ReduxAdapter",{enumerable:true,get:function(){return ReduxAdapter}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ReduxStateInstance=class ReduxStateInstance{get(){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const state=this.store.getState();return state[this.sliceName]??this.previousValue}set(valueOrUpdater){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const currentValue=this.get();let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(currentValue)}else{newValue=valueOrUpdater}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,currentValue)}if(processedValue===currentValue){return}this.previousValue=currentValue;const action=this.actions.setValue(processedValue);this.store.dispatch(action);if(this.devMode){console.debug(`[ReduxStateInstance] Updated: ${String(this.id)}`,{previous:currentValue,current:processedValue,action})}}subscribe(subscriber){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}return()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;if(this.unsubscribeStore){this.unsubscribeStore();this.unsubscribeStore=undefined}this.subscribers.clear();if(this.devMode){console.debug(`[ReduxStateInstance] Destroyed: ${String(this.id)}`)}}isDestroyed(){return this.destroyed}notifySubscribers(){if(this.destroyed){return}try{const currentValue=this.get();if(currentValue===this.previousValue){return}const previousValue=this.previousValue;this.previousValue=currentValue;const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(currentValue,previousValue)}catch(error){console.error(`[ReduxStateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}catch(error){console.error(`[ReduxStateInstance] Error getting state for ${String(this.id)}:`,error)}}constructor(store,sliceName,actions,initialValue,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"store",void 0);_define_property(this,"sliceName",void 0);_define_property(this,"actions",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"unsubscribeStore",void 0);_define_property(this,"destroyed",false);_define_property(this,"devMode",void 0);_define_property(this,"middleware",void 0);_define_property(this,"previousValue",void 0);this.store=store;this.sliceName=sliceName;this.actions=actions;this.id=options.id??Symbol("ReduxStateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];this.previousValue=initialValue;this.unsubscribeStore=this.store.subscribe(()=>{this.notifySubscribers()});if(this.devMode){console.debug(`[ReduxStateInstance] Created: ${String(this.id)}`,{scope:this.scope,sliceName:this.sliceName,initialValue})}}};let DynamicReducerManager=class DynamicReducerManager{addReducer(key,reducer){this.reducers.set(key,reducer)}removeReducer(key){this.reducers.delete(key)}getRootReducer(){return this.rootReducer}hasReducer(key){return this.reducers.has(key)}constructor(){_define_property(this,"reducers",new Map);_define_property(this,"rootReducer",void 0);this.rootReducer=(state,action)=>{const stateRecord=state??{};const newState={...stateRecord};for(const[key,reducer]of this.reducers.entries()){newState[key]=reducer(stateRecord[key],action)}return newState}}};let ReduxAdapter=class ReduxAdapter{checkReduxAvailable(){}getOrCreateStore(){if(this.store){return this.store}try{const{configureStore}=require("@reduxjs/toolkit");this.store=configureStore({reducer:this.reducerManager.getRootReducer(),devTools:this.devMode,middleware:undefined});if(this.devMode){console.debug("[ReduxAdapter] Redux store created")}return this.store}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createSlice(sliceName,initialValue){try{const{createSlice}=require("@reduxjs/toolkit");const slice=createSlice({name:sliceName,initialState:initialValue,reducers:{setValue:(_state,action)=>{return action.payload??initialValue}}});return slice}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createInstance(initialValue,options){if(this.destroyed){throw new Error("ReduxAdapter has been destroyed")}const store=this.getOrCreateStore();const sliceName=options?.id?`secra_${String(options.id)}`:`secra_slice_${++this.sliceCounter}`;const slice=this.createSlice(sliceName,initialValue);if(!this.reducerManager.hasReducer(sliceName)){this.reducerManager.addReducer(sliceName,slice.reducer);store.replaceReducer(this.reducerManager.getRootReducer())}const instance=new ReduxStateInstance(store,sliceName,slice.actions,initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode??this.devMode,middleware:options?.middleware});this.instances.add(instance);this.sliceToInstance.set(sliceName,instance);if(this.devMode){console.debug(`[ReduxAdapter] Created instance: ${String(instance.getId())}`,{sliceName,scope:options?.scope})}return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}for(const sliceName of this.sliceToInstance.keys()){this.reducerManager.removeReducer(sliceName)}if(this.store){this.store.replaceReducer(this.reducerManager.getRootReducer())}this.instances.clear();this.sliceToInstance.clear();this.store=null;this.destroyed=true;if(this.devMode){console.debug("[ReduxAdapter] Destroyed")}}getName(){return this.name}constructor(options){_define_property(this,"name","ReduxAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set);_define_property(this,"store",null);_define_property(this,"sliceCounter",0);_define_property(this,"sliceToInstance",new Map);_define_property(this,"reducerManager",void 0);_define_property(this,"devMode",void 0);this.devMode=options?.devMode??false;this.reducerManager=new DynamicReducerManager;this.store=options?.store??null;this.checkReduxAvailable()}};
@@ -1,129 +0,0 @@
1
- /**
2
- * Redux Toolkit 适配器
3
- *
4
- * 将 Redux Toolkit store 映射到 Secra 状态抽象
5
- *
6
- * 使用说明:
7
- * 1. 需要安装 @reduxjs/toolkit 作为 peerDependency
8
- * 2. 每个状态实例对应一个 Redux slice
9
- * 3. 支持 Redux DevTools 集成(如果可用)
10
- * 4. 支持中间件和开发模式
11
- *
12
- * @example
13
- * ```typescript
14
- * import { ReduxAdapter } from '@vlian/framework/state';
15
- *
16
- * const adapter = new ReduxAdapter({ devMode: true });
17
- * const state = adapter.createInstance(0, { id: 'counter' });
18
- *
19
- * state.set(1);
20
- * console.log(state.get()); // 1
21
- * ```
22
- */
23
- import type { IStateAdapter, IStateInstance, StateInstanceOptions } from '../types';
24
- /**
25
- * Redux 相关类型定义(如果 Redux 不可用,这些类型将用于类型检查)
26
- */
27
- type ReduxStore = {
28
- dispatch: (action: unknown) => unknown;
29
- getState: () => Record<string, unknown>;
30
- subscribe: (listener: () => void) => () => void;
31
- replaceReducer: (nextReducer: (state: unknown, action: unknown) => unknown) => void;
32
- };
33
- /**
34
- * Redux Toolkit 适配器配置选项
35
- */
36
- export interface ReduxAdapterOptions {
37
- /**
38
- * 是否启用开发模式
39
- */
40
- devMode?: boolean;
41
- /**
42
- * 自定义 Redux store(可选)
43
- * 如果不提供,将创建一个新的 store
44
- */
45
- store?: ReduxStore;
46
- /**
47
- * Redux store 配置选项(仅在创建新 store 时使用)
48
- */
49
- storeConfig?: {
50
- /**
51
- * 是否启用 Redux DevTools
52
- */
53
- devTools?: boolean;
54
- /**
55
- * Redux 中间件数组
56
- */
57
- middleware?: unknown[];
58
- };
59
- }
60
- /**
61
- * Redux Toolkit 适配器
62
- *
63
- * 将 Redux Toolkit store 映射到 Secra 状态抽象
64
- */
65
- export declare class ReduxAdapter implements IStateAdapter {
66
- /**
67
- * 适配器名称
68
- */
69
- private readonly name;
70
- /**
71
- * 是否已销毁
72
- */
73
- private destroyed;
74
- /**
75
- * 创建的状态实例集合
76
- */
77
- private readonly instances;
78
- /**
79
- * Redux store 实例
80
- */
81
- private store;
82
- /**
83
- * Redux slice 名称计数器(用于生成唯一的 slice 名称)
84
- */
85
- private sliceCounter;
86
- /**
87
- * Redux slice 名称到状态实例的映射
88
- */
89
- private readonly sliceToInstance;
90
- /**
91
- * 动态 reducer 管理器
92
- */
93
- private readonly reducerManager;
94
- /**
95
- * 是否启用开发模式
96
- */
97
- private readonly devMode;
98
- /**
99
- * 构造函数
100
- *
101
- * @param options - 适配器配置选项
102
- */
103
- constructor(options?: ReduxAdapterOptions);
104
- /**
105
- * 检查 Redux 是否可用
106
- */
107
- private checkReduxAvailable;
108
- /**
109
- * 获取或创建 Redux store
110
- */
111
- private getOrCreateStore;
112
- /**
113
- * 创建 Redux slice
114
- */
115
- private createSlice;
116
- /**
117
- * 创建状态实例
118
- */
119
- createInstance<T = unknown>(initialValue: T, options?: StateInstanceOptions): IStateInstance<T>;
120
- /**
121
- * 销毁适配器
122
- */
123
- destroy(): void;
124
- /**
125
- * 获取适配器名称
126
- */
127
- getName(): string;
128
- }
129
- export {};
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ReduxStateInstance=class ReduxStateInstance{get(){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const state=this.store.getState();return state[this.sliceName]??this.previousValue}set(valueOrUpdater){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}const currentValue=this.get();let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(currentValue)}else{newValue=valueOrUpdater}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,currentValue)}if(processedValue===currentValue){return}this.previousValue=currentValue;const action=this.actions.setValue(processedValue);this.store.dispatch(action);if(this.devMode){console.debug(`[ReduxStateInstance] Updated: ${String(this.id)}`,{previous:currentValue,current:processedValue,action})}}subscribe(subscriber){if(this.destroyed){throw new Error(`ReduxStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}return()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[ReduxStateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;if(this.unsubscribeStore){this.unsubscribeStore();this.unsubscribeStore=undefined}this.subscribers.clear();if(this.devMode){console.debug(`[ReduxStateInstance] Destroyed: ${String(this.id)}`)}}isDestroyed(){return this.destroyed}notifySubscribers(){if(this.destroyed){return}try{const currentValue=this.get();if(currentValue===this.previousValue){return}const previousValue=this.previousValue;this.previousValue=currentValue;const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(currentValue,previousValue)}catch(error){console.error(`[ReduxStateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}catch(error){console.error(`[ReduxStateInstance] Error getting state for ${String(this.id)}:`,error)}}constructor(store,sliceName,actions,initialValue,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"store",void 0);_define_property(this,"sliceName",void 0);_define_property(this,"actions",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"unsubscribeStore",void 0);_define_property(this,"destroyed",false);_define_property(this,"devMode",void 0);_define_property(this,"middleware",void 0);_define_property(this,"previousValue",void 0);this.store=store;this.sliceName=sliceName;this.actions=actions;this.id=options.id??Symbol("ReduxStateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];this.previousValue=initialValue;this.unsubscribeStore=this.store.subscribe(()=>{this.notifySubscribers()});if(this.devMode){console.debug(`[ReduxStateInstance] Created: ${String(this.id)}`,{scope:this.scope,sliceName:this.sliceName,initialValue})}}};let DynamicReducerManager=class DynamicReducerManager{addReducer(key,reducer){this.reducers.set(key,reducer)}removeReducer(key){this.reducers.delete(key)}getRootReducer(){return this.rootReducer}hasReducer(key){return this.reducers.has(key)}constructor(){_define_property(this,"reducers",new Map);_define_property(this,"rootReducer",void 0);this.rootReducer=(state,action)=>{const stateRecord=state??{};const newState={...stateRecord};for(const[key,reducer]of this.reducers.entries()){newState[key]=reducer(stateRecord[key],action)}return newState}}};export class ReduxAdapter{checkReduxAvailable(){}getOrCreateStore(){if(this.store){return this.store}try{const{configureStore}=require("@reduxjs/toolkit");this.store=configureStore({reducer:this.reducerManager.getRootReducer(),devTools:this.devMode,middleware:undefined});if(this.devMode){console.debug("[ReduxAdapter] Redux store created")}return this.store}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createSlice(sliceName,initialValue){try{const{createSlice}=require("@reduxjs/toolkit");const slice=createSlice({name:sliceName,initialState:initialValue,reducers:{setValue:(_state,action)=>{return action.payload??initialValue}}});return slice}catch(error){throw new Error("ReduxAdapter requires @reduxjs/toolkit to be installed. "+"Please install it: npm install @reduxjs/toolkit\n"+`Original error: ${error instanceof Error?error.message:String(error)}`)}}createInstance(initialValue,options){if(this.destroyed){throw new Error("ReduxAdapter has been destroyed")}const store=this.getOrCreateStore();const sliceName=options?.id?`secra_${String(options.id)}`:`secra_slice_${++this.sliceCounter}`;const slice=this.createSlice(sliceName,initialValue);if(!this.reducerManager.hasReducer(sliceName)){this.reducerManager.addReducer(sliceName,slice.reducer);store.replaceReducer(this.reducerManager.getRootReducer())}const instance=new ReduxStateInstance(store,sliceName,slice.actions,initialValue,{id:options?.id,scope:options?.scope,devMode:options?.devMode??this.devMode,middleware:options?.middleware});this.instances.add(instance);this.sliceToInstance.set(sliceName,instance);if(this.devMode){console.debug(`[ReduxAdapter] Created instance: ${String(instance.getId())}`,{sliceName,scope:options?.scope})}return instance}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}for(const sliceName of this.sliceToInstance.keys()){this.reducerManager.removeReducer(sliceName)}if(this.store){this.store.replaceReducer(this.reducerManager.getRootReducer())}this.instances.clear();this.sliceToInstance.clear();this.store=null;this.destroyed=true;if(this.devMode){console.debug("[ReduxAdapter] Destroyed")}}getName(){return this.name}constructor(options){_define_property(this,"name","ReduxAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set);_define_property(this,"store",null);_define_property(this,"sliceCounter",0);_define_property(this,"sliceToInstance",new Map);_define_property(this,"reducerManager",void 0);_define_property(this,"devMode",void 0);this.devMode=options?.devMode??false;this.reducerManager=new DynamicReducerManager;this.store=options?.store??null;this.checkReduxAvailable()}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"ZustandAdapter",{enumerable:true,get:function(){return ZustandAdapter}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ZustandAdapter=class ZustandAdapter{createInstance(_initialValue,_options){if(this.destroyed){throw new Error("Adapter has been destroyed")}throw new Error("ZustandAdapter is a placeholder implementation. "+"To use Zustand, you need to:\n"+"1. Install zustand\n"+"2. Implement a complete Zustand store integration\n"+"3. Map Zustand store methods to IStateInstance interface\n"+"See docs/state-manager.md for implementation guide.")}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}this.instances.clear();this.destroyed=true}getName(){return this.name}constructor(){_define_property(this,"name","ZustandAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set)}};
@@ -1,46 +0,0 @@
1
- /**
2
- * Zustand 适配器(占位实现)
3
- *
4
- * 这是一个适配器接口示例,展示如何将 Zustand 集成到 Secra 状态管理器
5
- *
6
- * ⚠️ 注意:这是一个占位实现,实际使用时需要安装 zustand 依赖
7
- */
8
- import type { IStateAdapter, IStateInstance, StateInstanceOptions } from '../types';
9
- /**
10
- * Zustand 适配器
11
- *
12
- * 将 Zustand store 映射到 Secra 状态抽象
13
- *
14
- * ⚠️ 这是一个占位实现,实际使用时需要:
15
- * 1. 安装 zustand
16
- * 2. 实现完整的 Zustand store 集成
17
- * 3. 将 Zustand store 的方法映射到 IStateInstance 接口
18
- */
19
- export declare class ZustandAdapter implements IStateAdapter {
20
- /**
21
- * 适配器名称
22
- */
23
- private readonly name;
24
- /**
25
- * 是否已销毁
26
- */
27
- private destroyed;
28
- /**
29
- * 创建的状态实例集合
30
- */
31
- private readonly instances;
32
- /**
33
- * 创建状态实例
34
- *
35
- * ⚠️ 占位实现:实际使用时需要创建 Zustand store 并映射到 IStateInstance
36
- */
37
- createInstance<T>(_initialValue: T, _options?: StateInstanceOptions): IStateInstance<T>;
38
- /**
39
- * 销毁适配器
40
- */
41
- destroy(): void;
42
- /**
43
- * 获取适配器名称
44
- */
45
- getName(): string;
46
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export class ZustandAdapter{createInstance(_initialValue,_options){if(this.destroyed){throw new Error("Adapter has been destroyed")}throw new Error("ZustandAdapter is a placeholder implementation. "+"To use Zustand, you need to:\n"+"1. Install zustand\n"+"2. Implement a complete Zustand store integration\n"+"3. Map Zustand store methods to IStateInstance interface\n"+"See docs/state-manager.md for implementation guide.")}destroy(){if(this.destroyed){return}for(const instance of this.instances){instance.destroy()}this.instances.clear();this.destroyed=true}getName(){return this.name}constructor(){_define_property(this,"name","ZustandAdapter");_define_property(this,"destroyed",false);_define_property(this,"instances",new Set)}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get AdapterFactory(){return _AdapterFactory.AdapterFactory},get DefaultAdapter(){return _DefaultAdapter.DefaultAdapter},get ReduxAdapter(){return _ReduxAdapter.ReduxAdapter},get ZustandAdapter(){return _ZustandAdapter.ZustandAdapter}});const _DefaultAdapter=require("./DefaultAdapter");const _AdapterFactory=require("./AdapterFactory");const _ReduxAdapter=require("./ReduxAdapter");const _ZustandAdapter=require("./ZustandAdapter");_export_star(require("./types"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
@@ -1,8 +0,0 @@
1
- /**
2
- * 状态适配器模块导出
3
- */
4
- export { DefaultAdapter } from './DefaultAdapter';
5
- export { AdapterFactory } from './AdapterFactory';
6
- export { ReduxAdapter, type ReduxAdapterOptions } from './ReduxAdapter';
7
- export { ZustandAdapter } from './ZustandAdapter';
8
- export * from './types';
@@ -1 +0,0 @@
1
- export{DefaultAdapter}from"./DefaultAdapter";export{AdapterFactory}from"./AdapterFactory";export{ReduxAdapter}from"./ReduxAdapter";export{ZustandAdapter}from"./ZustandAdapter";export*from"./types";
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});_export_star(require("../types"),exports);function _export_star(from,to){Object.keys(from).forEach(function(k){if(k!=="default"&&!Object.prototype.hasOwnProperty.call(to,k)){Object.defineProperty(to,k,{enumerable:true,get:function(){return from[k]}})}});return from}
@@ -1,4 +0,0 @@
1
- /**
2
- * 状态适配器类型定义
3
- */
4
- export * from '../types';
@@ -1 +0,0 @@
1
- export*from"../types";
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"DerivedStateInstance",{enumerable:true,get:function(){return DerivedStateInstance}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let DerivedStateInstance=class DerivedStateInstance{get(){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}return this.value}set(_valueOrUpdater){throw new Error("Derived state cannot be set directly. Modify the dependency states instead.")}subscribe(subscriber){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);return()=>{this.subscribers.delete(subscriber)}}getId(){return this.id}getScope(){return this.scope}getDependencies(){return this.config.dependencies}recompute(){if(this.destroyed||this.recomputing){return}this.recomputing=true;try{const dependencyValues=this.config.dependencies.map(dep=>dep.get());const newValue=this.config.derive(dependencyValues);const hasChanged=this.config.equalityCheck?!this.config.equalityCheck(this.value,newValue):this.value!==newValue;if(hasChanged){const previousValue=this.value;this.value=newValue;this.notifySubscribers(this.value,previousValue)}}catch(error){console.error(`[DerivedStateInstance] Error recomputing ${String(this.id)}:`,error)}finally{this.recomputing=false}}destroy(){if(this.destroyed){return}this.destroyed=true;for(const unsubscribe of this.dependencyUnsubscribes){unsubscribe()}this.dependencyUnsubscribes.length=0;this.subscribers.clear()}isDestroyed(){return this.destroyed}setupDependencies(){for(const dependency of this.config.dependencies){const unsubscribe=dependency.subscribe(()=>{this.recompute()});this.dependencyUnsubscribes.push(unsubscribe)}}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous)}catch(error){console.error(`[DerivedStateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}constructor(config,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"config",void 0);_define_property(this,"value",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"dependencyUnsubscribes",[]);_define_property(this,"destroyed",false);_define_property(this,"recomputing",false);this.config=config;this.id=options.id??Symbol("DerivedStateInstance");this.scope=options.scope;this.setupDependencies();this.recompute()}};
@@ -1,100 +0,0 @@
1
- /**
2
- * 派生状态实例实现
3
- */
4
- import type { IDerivedStateInstance, IStateInstance, DerivedStateConfig, StateInstanceId, StateScope, StateSubscriber, StateUpdater, Unsubscribe } from '../types';
5
- /**
6
- * 派生状态实例
7
- *
8
- * 派生状态不直接存储值,而是基于依赖状态自动计算
9
- *
10
- * @template T - 派生状态值类型
11
- * @template D - 依赖状态实例数组类型
12
- */
13
- export declare class DerivedStateInstance<T, D extends readonly IStateInstance[]> implements IDerivedStateInstance<T> {
14
- /**
15
- * 状态实例标识符
16
- */
17
- private readonly id;
18
- /**
19
- * 状态作用域
20
- */
21
- private readonly scope?;
22
- /**
23
- * 派生状态配置
24
- */
25
- private readonly config;
26
- /**
27
- * 当前派生值
28
- */
29
- private value;
30
- /**
31
- * 订阅者集合
32
- */
33
- private readonly subscribers;
34
- /**
35
- * 依赖状态的取消订阅函数数组
36
- */
37
- private readonly dependencyUnsubscribes;
38
- /**
39
- * 是否已销毁
40
- */
41
- private destroyed;
42
- /**
43
- * 是否正在重新计算
44
- */
45
- private recomputing;
46
- /**
47
- * 构造函数
48
- *
49
- * @param config - 派生状态配置
50
- * @param options - 状态实例配置选项
51
- */
52
- constructor(config: DerivedStateConfig<T, D>, options?: {
53
- id?: StateInstanceId;
54
- scope?: StateScope;
55
- });
56
- /**
57
- * 获取当前状态值
58
- */
59
- get(): T;
60
- /**
61
- * 派生状态不支持直接设置值
62
- */
63
- set(_valueOrUpdater: T | StateUpdater<T>): void;
64
- /**
65
- * 订阅状态变化
66
- */
67
- subscribe(subscriber: StateSubscriber<T>): Unsubscribe;
68
- /**
69
- * 获取状态实例标识符
70
- */
71
- getId(): StateInstanceId;
72
- /**
73
- * 获取状态作用域
74
- */
75
- getScope(): StateScope | undefined;
76
- /**
77
- * 获取依赖的状态实例
78
- */
79
- getDependencies(): readonly IStateInstance[];
80
- /**
81
- * 手动重新计算派生状态
82
- */
83
- recompute(): void;
84
- /**
85
- * 销毁状态实例
86
- */
87
- destroy(): void;
88
- /**
89
- * 检查状态实例是否已销毁
90
- */
91
- isDestroyed(): boolean;
92
- /**
93
- * 设置依赖状态订阅
94
- */
95
- private setupDependencies;
96
- /**
97
- * 通知所有订阅者
98
- */
99
- private notifySubscribers;
100
- }
@@ -1 +0,0 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export class DerivedStateInstance{get(){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}return this.value}set(_valueOrUpdater){throw new Error("Derived state cannot be set directly. Modify the dependency states instead.")}subscribe(subscriber){if(this.destroyed){throw new Error(`DerivedStateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);return()=>{this.subscribers.delete(subscriber)}}getId(){return this.id}getScope(){return this.scope}getDependencies(){return this.config.dependencies}recompute(){if(this.destroyed||this.recomputing){return}this.recomputing=true;try{const dependencyValues=this.config.dependencies.map(dep=>dep.get());const newValue=this.config.derive(dependencyValues);const hasChanged=this.config.equalityCheck?!this.config.equalityCheck(this.value,newValue):this.value!==newValue;if(hasChanged){const previousValue=this.value;this.value=newValue;this.notifySubscribers(this.value,previousValue)}}catch(error){console.error(`[DerivedStateInstance] Error recomputing ${String(this.id)}:`,error)}finally{this.recomputing=false}}destroy(){if(this.destroyed){return}this.destroyed=true;for(const unsubscribe of this.dependencyUnsubscribes){unsubscribe()}this.dependencyUnsubscribes.length=0;this.subscribers.clear()}isDestroyed(){return this.destroyed}setupDependencies(){for(const dependency of this.config.dependencies){const unsubscribe=dependency.subscribe(()=>{this.recompute()});this.dependencyUnsubscribes.push(unsubscribe)}}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous)}catch(error){console.error(`[DerivedStateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}constructor(config,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"config",void 0);_define_property(this,"value",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"dependencyUnsubscribes",[]);_define_property(this,"destroyed",false);_define_property(this,"recomputing",false);this.config=config;this.id=options.id??Symbol("DerivedStateInstance");this.scope=options.scope;this.setupDependencies();this.recompute()}}
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"StateInstance",{enumerable:true,get:function(){return StateInstance}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let StateInstance=class StateInstance{get(){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}return this.value}set(valueOrUpdater){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}const previousValue=this.value;let newValue;if(typeof valueOrUpdater==="function"){newValue=valueOrUpdater(this.value)}else{newValue=valueOrUpdater}let processedValue=newValue;for(const middleware of this.middleware){processedValue=middleware(processedValue,previousValue)}if(processedValue===this.value){return}this.value=processedValue;if(this.devMode){console.debug(`[StateInstance] Updated: ${String(this.id)}`,{previous:previousValue,current:this.value})}this.notifySubscribers(this.value,previousValue)}subscribe(subscriber){if(this.destroyed){throw new Error(`StateInstance ${String(this.id)} has been destroyed`)}this.subscribers.add(subscriber);if(this.devMode){console.debug(`[StateInstance] Subscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}return()=>{this.subscribers.delete(subscriber);if(this.devMode){console.debug(`[StateInstance] Unsubscribed: ${String(this.id)}`,{subscriberCount:this.subscribers.size})}}}getId(){return this.id}getScope(){return this.scope}destroy(){if(this.destroyed){return}this.destroyed=true;this.subscribers.clear();this.value=undefined;if(this.devMode){console.debug(`[StateInstance] Destroyed: ${String(this.id)}`)}}isDestroyed(){return this.destroyed}notifySubscribers(value,previous){const subscribers=Array.from(this.subscribers);for(const subscriber of subscribers){try{subscriber(value,previous)}catch(error){console.error(`[StateInstance] Error in subscriber for ${String(this.id)}:`,error)}}}constructor(initialValue,options={}){_define_property(this,"id",void 0);_define_property(this,"scope",void 0);_define_property(this,"value",void 0);_define_property(this,"subscribers",new Set);_define_property(this,"destroyed",false);_define_property(this,"devMode",void 0);_define_property(this,"middleware",void 0);this.value=initialValue;this.id=options.id??Symbol("StateInstance");this.scope=options.scope;this.devMode=options.devMode??false;this.middleware=options.middleware??[];if(this.devMode){console.debug(`[StateInstance] Created: ${String(this.id)}`,{scope:this.scope,initialValue:this.value})}}};