@composy/store-core 0.0.1 → 0.0.2
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/CHANGELOG.md +64 -3
- package/README.md +196 -172
- package/dist/index.js +1331 -1115
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +578 -417
- package/dist/index.min.js.map +1 -1
- package/es/.dts-output-manifest.json +1 -0
- package/es/.dts.tsbuildinfo +1 -0
- package/es/core/async-action.d.ts +1 -71
- package/es/core/async-action.js +83 -35
- package/es/core/async-action.js.map +1 -1
- package/es/core/base-store.d.ts +27 -62
- package/es/core/base-store.js +174 -74
- package/es/core/base-store.js.map +1 -1
- package/es/core/batch-manager.d.ts +0 -1
- package/es/core/batch-manager.js +15 -2
- package/es/core/batch-manager.js.map +1 -1
- package/es/core/create-store.d.ts +3 -3
- package/es/core/create-store.js +3 -3
- package/es/core/create-store.js.map +1 -1
- package/es/core/event-bus.d.ts +0 -1
- package/es/core/event-bus.js +1 -1
- package/es/core/event-bus.js.map +1 -1
- package/es/core/index.d.ts +1 -2
- package/es/core/index.js +2 -2
- package/es/core/pub-sub.d.ts +0 -1
- package/es/core/pub-sub.js +1 -1
- package/es/core/pub-sub.js.map +1 -1
- package/es/engine/index.d.ts +0 -1
- package/es/engine/index.js +1 -1
- package/es/engine/plugin.d.ts +0 -1
- package/es/engine/plugin.js +11 -2
- package/es/engine/plugin.js.map +1 -1
- package/es/engine/types.d.ts +0 -1
- package/es/engine/types.js +1 -1
- package/es/errors/index.d.ts +0 -1
- package/es/errors/index.js +17 -1
- package/es/errors/index.js.map +1 -1
- package/es/index.d.ts +3 -4
- package/es/index.js +8 -8
- package/es/index.js.map +1 -1
- package/es/middleware/index.d.ts +3 -4
- package/es/middleware/index.js +2 -2
- package/es/middleware/logger.d.ts +0 -1
- package/es/middleware/logger.js +2 -2
- package/es/middleware/logger.js.map +1 -1
- package/es/middleware/middleware-manager.d.ts +0 -1
- package/es/middleware/middleware-manager.js +5 -2
- package/es/middleware/middleware-manager.js.map +1 -1
- package/es/middleware/persist.d.ts +0 -1
- package/es/middleware/persist.js +3 -3
- package/es/middleware/persist.js.map +1 -1
- package/es/middleware/time-travel.d.ts +0 -1
- package/es/middleware/time-travel.js +1 -1
- package/es/middleware/time-travel.js.map +1 -1
- package/es/middleware/validation.d.ts +0 -1
- package/es/middleware/validation.js +2 -2
- package/es/middleware/validation.js.map +1 -1
- package/es/plugins/define-plugin.d.ts +1 -2
- package/es/plugins/define-plugin.js +2 -2
- package/es/plugins/define-plugin.js.map +1 -1
- package/es/plugins/index.d.ts +0 -1
- package/es/plugins/index.js +2 -2
- package/es/plugins/plugin-manager.d.ts +1 -31
- package/es/plugins/plugin-manager.js +58 -27
- package/es/plugins/plugin-manager.js.map +1 -1
- package/es/types/action.d.ts +2 -0
- package/es/types/action.js +10 -0
- package/es/types/batch.d.ts +2 -0
- package/es/types/batch.js +10 -0
- package/es/types/event.d.ts +2 -0
- package/es/types/event.js +10 -0
- package/es/types/index.d.ts +2 -3
- package/es/types/index.js +1 -1
- package/es/types/middleware.d.ts +10 -2
- package/es/types/middleware.js +1 -1
- package/es/types/mutation.d.ts +2 -0
- package/es/types/mutation.js +10 -0
- package/es/types/plugin.d.ts +4 -1
- package/es/types/plugin.js +1 -1
- package/es/types/state.d.ts +2 -0
- package/es/types/state.js +10 -0
- package/es/types/store.d.ts +19 -1
- package/es/types/store.js +1 -1
- package/es/types/subscription.d.ts +7 -2
- package/es/types/subscription.js +1 -1
- package/es/types/time-travel.d.ts +2 -0
- package/es/types/time-travel.js +10 -0
- package/es/types/utility.d.ts +3 -4
- package/es/types/utility.js +1 -1
- package/es/utils/debounce-throttle.d.ts +0 -1
- package/es/utils/debounce-throttle.js +1 -1
- package/es/utils/debounce-throttle.js.map +1 -1
- package/es/utils/deep-clone.d.ts +0 -1
- package/es/utils/deep-clone.js +1 -1
- package/es/utils/deep-clone.js.map +1 -1
- package/es/utils/index.d.ts +4 -5
- package/es/utils/index.js +1 -1
- package/es/utils/selector.d.ts +0 -1
- package/es/utils/selector.js +1 -1
- package/es/utils/selector.js.map +1 -1
- package/esm/core/async-action.js +83 -35
- package/esm/core/async-action.js.map +1 -1
- package/esm/core/base-store.js +174 -74
- package/esm/core/base-store.js.map +1 -1
- package/esm/core/batch-manager.js +15 -2
- package/esm/core/batch-manager.js.map +1 -1
- package/esm/core/create-store.js +3 -3
- package/esm/core/create-store.js.map +1 -1
- package/esm/core/event-bus.js +1 -1
- package/esm/core/event-bus.js.map +1 -1
- package/esm/core/index.js +2 -2
- package/esm/core/pub-sub.js +1 -1
- package/esm/core/pub-sub.js.map +1 -1
- package/esm/engine/index.js +1 -1
- package/esm/engine/plugin.js +11 -2
- package/esm/engine/plugin.js.map +1 -1
- package/esm/errors/index.js +17 -1
- package/esm/errors/index.js.map +1 -1
- package/esm/index.js +8 -8
- package/esm/index.js.map +1 -1
- package/esm/middleware/logger.js +2 -2
- package/esm/middleware/logger.js.map +1 -1
- package/esm/middleware/middleware-manager.js +5 -2
- package/esm/middleware/middleware-manager.js.map +1 -1
- package/esm/middleware/persist.js +3 -3
- package/esm/middleware/persist.js.map +1 -1
- package/esm/middleware/time-travel.js +1 -1
- package/esm/middleware/time-travel.js.map +1 -1
- package/esm/middleware/validation.js +2 -2
- package/esm/middleware/validation.js.map +1 -1
- package/esm/plugins/define-plugin.js +2 -2
- package/esm/plugins/define-plugin.js.map +1 -1
- package/esm/plugins/plugin-manager.js +58 -27
- package/esm/plugins/plugin-manager.js.map +1 -1
- package/esm/utils/debounce-throttle.js +1 -1
- package/esm/utils/debounce-throttle.js.map +1 -1
- package/esm/utils/deep-clone.js +1 -1
- package/esm/utils/deep-clone.js.map +1 -1
- package/esm/utils/selector.js +1 -1
- package/esm/utils/selector.js.map +1 -1
- package/lib/core/async-action.cjs +83 -35
- package/lib/core/async-action.cjs.map +1 -1
- package/lib/core/async-action.d.cts +25 -0
- package/lib/core/base-store.cjs +174 -74
- package/lib/core/base-store.cjs.map +1 -1
- package/lib/core/base-store.d.cts +50 -0
- package/lib/core/batch-manager.cjs +15 -2
- package/lib/core/batch-manager.cjs.map +1 -1
- package/{esm/core/batch-manager.d.ts → lib/core/batch-manager.d.cts} +0 -1
- package/lib/core/create-store.cjs +3 -3
- package/lib/core/create-store.cjs.map +1 -1
- package/lib/core/{create-store.d.ts → create-store.d.cts} +3 -3
- package/lib/core/event-bus.cjs +1 -1
- package/lib/core/event-bus.cjs.map +1 -1
- package/lib/core/{event-bus.d.ts → event-bus.d.cts} +0 -1
- package/lib/core/index.cjs +2 -2
- package/{esm/core/index.d.ts → lib/core/index.d.cts} +1 -2
- package/lib/core/pub-sub.cjs +1 -1
- package/lib/core/pub-sub.cjs.map +1 -1
- package/lib/core/{pub-sub.d.ts → pub-sub.d.cts} +0 -1
- package/lib/engine/index.cjs +1 -1
- package/{esm/engine/index.d.ts → lib/engine/index.d.cts} +0 -1
- package/lib/engine/plugin.cjs +11 -2
- package/lib/engine/plugin.cjs.map +1 -1
- package/{esm/engine/plugin.d.ts → lib/engine/plugin.d.cts} +0 -1
- package/lib/engine/types.cjs +1 -1
- package/lib/engine/{types.d.ts → types.d.cts} +0 -1
- package/lib/errors/index.cjs +17 -1
- package/lib/errors/index.cjs.map +1 -1
- package/lib/errors/{index.d.ts → index.d.cts} +0 -1
- package/lib/index.cjs +8 -8
- package/lib/index.cjs.map +1 -1
- package/lib/{index.d.ts → index.d.cts} +3 -4
- package/lib/middleware/index.cjs +2 -2
- package/lib/middleware/{index.d.ts → index.d.cts} +3 -4
- package/lib/middleware/logger.cjs +2 -2
- package/lib/middleware/logger.cjs.map +1 -1
- package/lib/middleware/{logger.d.ts → logger.d.cts} +0 -1
- package/lib/middleware/middleware-manager.cjs +5 -2
- package/lib/middleware/middleware-manager.cjs.map +1 -1
- package/lib/middleware/{middleware-manager.d.ts → middleware-manager.d.cts} +0 -1
- package/lib/middleware/persist.cjs +3 -3
- package/lib/middleware/persist.cjs.map +1 -1
- package/{esm/middleware/persist.d.ts → lib/middleware/persist.d.cts} +0 -1
- package/lib/middleware/time-travel.cjs +1 -1
- package/lib/middleware/time-travel.cjs.map +1 -1
- package/{esm/middleware/time-travel.d.ts → lib/middleware/time-travel.d.cts} +0 -1
- package/lib/middleware/validation.cjs +2 -2
- package/lib/middleware/validation.cjs.map +1 -1
- package/{esm/middleware/validation.d.ts → lib/middleware/validation.d.cts} +0 -1
- package/lib/plugins/define-plugin.cjs +2 -2
- package/lib/plugins/define-plugin.cjs.map +1 -1
- package/{esm/plugins/define-plugin.d.ts → lib/plugins/define-plugin.d.cts} +1 -2
- package/lib/plugins/index.cjs +2 -2
- package/{esm/plugins/index.d.ts → lib/plugins/index.d.cts} +0 -1
- package/lib/plugins/plugin-manager.cjs +58 -27
- package/lib/plugins/plugin-manager.cjs.map +1 -1
- package/lib/plugins/plugin-manager.d.cts +5 -0
- package/lib/types/action.cjs +12 -0
- package/lib/types/action.d.cts +2 -0
- package/lib/types/batch.cjs +12 -0
- package/lib/types/batch.d.cts +2 -0
- package/lib/types/event.cjs +12 -0
- package/lib/types/event.d.cts +2 -0
- package/lib/types/index.cjs +1 -1
- package/{esm/types/index.d.ts → lib/types/index.d.cts} +2 -3
- package/lib/types/middleware.cjs +1 -1
- package/lib/types/{middleware.d.ts → middleware.d.cts} +10 -2
- package/lib/types/mutation.cjs +12 -0
- package/lib/types/mutation.d.cts +2 -0
- package/lib/types/plugin.cjs +1 -1
- package/lib/types/{plugin.d.ts → plugin.d.cts} +4 -1
- package/lib/types/state.cjs +12 -0
- package/lib/types/state.d.cts +2 -0
- package/lib/types/store.cjs +1 -1
- package/lib/types/{store.d.ts → store.d.cts} +19 -1
- package/lib/types/subscription.cjs +1 -1
- package/lib/types/{subscription.d.ts → subscription.d.cts} +7 -2
- package/lib/types/time-travel.cjs +12 -0
- package/lib/types/time-travel.d.cts +2 -0
- package/lib/types/utility.cjs +1 -1
- package/lib/types/{utility.d.ts → utility.d.cts} +3 -4
- package/lib/utils/debounce-throttle.cjs +1 -1
- package/lib/utils/debounce-throttle.cjs.map +1 -1
- package/{esm/utils/debounce-throttle.d.ts → lib/utils/debounce-throttle.d.cts} +0 -1
- package/lib/utils/deep-clone.cjs +1 -1
- package/lib/utils/deep-clone.cjs.map +1 -1
- package/lib/utils/{deep-clone.d.ts → deep-clone.d.cts} +0 -1
- package/lib/utils/index.cjs +1 -1
- package/lib/utils/{index.d.ts → index.d.cts} +4 -5
- package/lib/utils/selector.cjs +1 -1
- package/lib/utils/selector.cjs.map +1 -1
- package/lib/utils/{selector.d.ts → selector.d.cts} +0 -1
- package/package.json +14 -11
- package/es/core/async-action.d.ts.map +0 -1
- package/es/core/base-store.d.ts.map +0 -1
- package/es/core/batch-manager.d.ts.map +0 -1
- package/es/core/create-store.d.ts.map +0 -1
- package/es/core/event-bus.d.ts.map +0 -1
- package/es/core/index.d.ts.map +0 -1
- package/es/core/pub-sub.d.ts.map +0 -1
- package/es/engine/index.d.ts.map +0 -1
- package/es/engine/plugin.d.ts.map +0 -1
- package/es/engine/types.d.ts.map +0 -1
- package/es/errors/index.d.ts.map +0 -1
- package/es/index.d.ts.map +0 -1
- package/es/middleware/index.d.ts.map +0 -1
- package/es/middleware/logger.d.ts.map +0 -1
- package/es/middleware/middleware-manager.d.ts.map +0 -1
- package/es/middleware/persist.d.ts.map +0 -1
- package/es/middleware/time-travel.d.ts.map +0 -1
- package/es/middleware/validation.d.ts.map +0 -1
- package/es/plugins/define-plugin.d.ts.map +0 -1
- package/es/plugins/index.d.ts.map +0 -1
- package/es/plugins/plugin-manager.d.ts.map +0 -1
- package/es/types/index.d.ts.map +0 -1
- package/es/types/middleware.d.ts.map +0 -1
- package/es/types/plugin.d.ts.map +0 -1
- package/es/types/store.d.ts.map +0 -1
- package/es/types/subscription.d.ts.map +0 -1
- package/es/types/utility.d.ts.map +0 -1
- package/es/utils/debounce-throttle.d.ts.map +0 -1
- package/es/utils/deep-clone.d.ts.map +0 -1
- package/es/utils/index.d.ts.map +0 -1
- package/es/utils/selector.d.ts.map +0 -1
- package/esm/core/async-action.d.ts +0 -95
- package/esm/core/base-store.d.ts +0 -85
- package/esm/core/create-store.d.ts +0 -66
- package/esm/core/event-bus.d.ts +0 -34
- package/esm/core/pub-sub.d.ts +0 -41
- package/esm/engine/types.d.ts +0 -81
- package/esm/errors/index.d.ts +0 -208
- package/esm/index.d.ts +0 -27
- package/esm/middleware/index.d.ts +0 -13
- package/esm/middleware/logger.d.ts +0 -67
- package/esm/middleware/middleware-manager.d.ts +0 -40
- package/esm/plugins/plugin-manager.d.ts +0 -35
- package/esm/types/middleware.d.ts +0 -172
- package/esm/types/plugin.d.ts +0 -136
- package/esm/types/store.d.ts +0 -198
- package/esm/types/subscription.d.ts +0 -158
- package/esm/types/utility.d.ts +0 -312
- package/esm/utils/deep-clone.d.ts +0 -143
- package/esm/utils/index.d.ts +0 -13
- package/esm/utils/selector.d.ts +0 -213
- package/lib/core/async-action.d.ts +0 -95
- package/lib/core/base-store.d.ts +0 -85
- package/lib/core/batch-manager.d.ts +0 -46
- package/lib/core/index.d.ts +0 -14
- package/lib/engine/index.d.ts +0 -10
- package/lib/engine/plugin.d.ts +0 -20
- package/lib/middleware/persist.d.ts +0 -34
- package/lib/middleware/time-travel.d.ts +0 -30
- package/lib/middleware/validation.d.ts +0 -100
- package/lib/plugins/define-plugin.d.ts +0 -74
- package/lib/plugins/index.d.ts +0 -8
- package/lib/plugins/plugin-manager.d.ts +0 -35
- package/lib/types/index.d.ts +0 -12
- package/lib/utils/debounce-throttle.d.ts +0 -86
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Middleware, // 状态快照接口
|
|
2
|
-
StateTree, // 状态树类型
|
|
3
|
-
StoreId, // Store 标识类型
|
|
4
|
-
TimeTravelController, // 时间旅行控制器接口
|
|
5
|
-
TimeTravelMiddlewareOptions } from '../types';
|
|
6
|
-
/**
|
|
7
|
-
* 创建时间旅行中间件
|
|
8
|
-
*
|
|
9
|
-
* 返回一个中间件函数和一个控制器对象:
|
|
10
|
-
* - 中间件负责拦截 state: 类型的操作,在操作前后记录状态快照
|
|
11
|
-
* - 控制器提供 undo/redo/goto/clear 等方法,用于在历史快照之间跳转
|
|
12
|
-
*
|
|
13
|
-
* @param options - 中间件配置选项(可选,与默认值合并)
|
|
14
|
-
* @returns 包含 middleware(中间件)和 controller(控制器)的对象
|
|
15
|
-
*/
|
|
16
|
-
export declare function createTimeTravelMiddleware(options?: TimeTravelMiddlewareOptions): {
|
|
17
|
-
middleware: Middleware;
|
|
18
|
-
controller: TimeTravelController;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* 外部设置恢复回调的辅助函数
|
|
22
|
-
* 将外部提供的状态恢复函数注入到时间旅行控制器中
|
|
23
|
-
*
|
|
24
|
-
* 使用场景:Store 运行时初始化时调用此函数,将控制器与 Store 的状态恢复逻辑连接
|
|
25
|
-
*
|
|
26
|
-
* @param controller - 时间旅行控制器实例
|
|
27
|
-
* @param callback - 恢复回调函数,接收 storeId 和已深拷贝的状态树
|
|
28
|
-
*/
|
|
29
|
-
export declare function setRestoreCallback(controller: TimeTravelController, callback: (storeId: StoreId, state: StateTree) => void): void;
|
|
30
|
-
//# sourceMappingURL=time-travel.d.ts.map
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 验证中间件
|
|
3
|
-
*
|
|
4
|
-
* 对状态变化进行规则校验,支持同步/异步校验器
|
|
5
|
-
* @module middleware/validation
|
|
6
|
-
*/
|
|
7
|
-
import type { Middleware, StateTree, StoreId } from '../types';
|
|
8
|
-
/**
|
|
9
|
-
* 单个字段校验规则
|
|
10
|
-
*/
|
|
11
|
-
export interface ValidationRule<T = unknown> {
|
|
12
|
-
/** 校验函数,返回 true 表示通过 */
|
|
13
|
-
validate: (value: T, state: StateTree) => boolean | Promise<boolean>;
|
|
14
|
-
/** 校验失败时的错误信息 */
|
|
15
|
-
message: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Store 校验规则集
|
|
19
|
-
*/
|
|
20
|
-
export type StoreValidationRules = Record<string, ValidationRule | ValidationRule[]>;
|
|
21
|
-
/**
|
|
22
|
-
* 校验错误
|
|
23
|
-
*/
|
|
24
|
-
export interface ValidationError {
|
|
25
|
-
/** Store ID */
|
|
26
|
-
storeId: StoreId;
|
|
27
|
-
/** 字段路径 */
|
|
28
|
-
field: string;
|
|
29
|
-
/** 错误信息 */
|
|
30
|
-
message: string;
|
|
31
|
-
/** 字段值 */
|
|
32
|
-
value: unknown;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 校验结果
|
|
36
|
-
*/
|
|
37
|
-
export interface ValidationResult {
|
|
38
|
-
/** 是否全部通过 */
|
|
39
|
-
valid: boolean;
|
|
40
|
-
/** 错误列表 */
|
|
41
|
-
errors: ValidationError[];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 验证中间件选项
|
|
45
|
-
*/
|
|
46
|
-
export interface ValidationMiddlewareOptions {
|
|
47
|
-
/** 按 Store ID 配置的校验规则 */
|
|
48
|
-
rules: Record<StoreId, StoreValidationRules>;
|
|
49
|
-
/** 校验失败时的回调 */
|
|
50
|
-
onValidationError?: (result: ValidationResult) => void;
|
|
51
|
-
/** 校验失败是否阻止状态变化 (默认 false,仅报告) */
|
|
52
|
-
blocking?: boolean;
|
|
53
|
-
/** 是否只在 state:patch 时校验 (默认 false,所有 state: 前缀均校验) */
|
|
54
|
-
patchOnly?: boolean;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 创建验证中间件
|
|
58
|
-
*
|
|
59
|
-
* 对状态变化进行规则校验,可选择阻止无效变化或仅报告错误
|
|
60
|
-
*
|
|
61
|
-
* @param options - 验证配置
|
|
62
|
-
* @returns 中间件实例和校验辅助 API
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const { middleware, validate, getErrors, clearErrors } = createValidationMiddleware({
|
|
67
|
-
* rules: {
|
|
68
|
-
* 'user-form': {
|
|
69
|
-
* name: {
|
|
70
|
-
* validate: (v) => typeof v === 'string' && v.length >= 2,
|
|
71
|
-
* message: 'Name must be at least 2 characters',
|
|
72
|
-
* },
|
|
73
|
-
* age: [
|
|
74
|
-
* { validate: (v) => typeof v === 'number', message: 'Age must be a number' },
|
|
75
|
-
* { validate: (v) => (v as number) >= 0 && (v as number) <= 150, message: 'Age must be 0-150' },
|
|
76
|
-
* ],
|
|
77
|
-
* email: {
|
|
78
|
-
* validate: (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(v)),
|
|
79
|
-
* message: 'Invalid email format',
|
|
80
|
-
* },
|
|
81
|
-
* },
|
|
82
|
-
* },
|
|
83
|
-
* onValidationError: (result) => {
|
|
84
|
-
* console.warn('Validation failed:', result.errors)
|
|
85
|
-
* },
|
|
86
|
-
* })
|
|
87
|
-
*
|
|
88
|
-
* manager.use(middleware)
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export declare function createValidationMiddleware(options: ValidationMiddlewareOptions): {
|
|
92
|
-
middleware: Middleware;
|
|
93
|
-
/** 手动校验某个 store 的当前状态 */
|
|
94
|
-
validate: (storeId: StoreId, state: StateTree) => Promise<ValidationResult>;
|
|
95
|
-
/** 获取最近一次的校验错误 */
|
|
96
|
-
getErrors: () => ValidationError[];
|
|
97
|
-
/** 清空错误 */
|
|
98
|
-
clearErrors: () => void;
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件定义辅助函数
|
|
3
|
-
*
|
|
4
|
-
* @module plugins/define-plugin
|
|
5
|
-
*/
|
|
6
|
-
import type { DefinePluginOptions, PluginFactory, StorePlugin } from '../types';
|
|
7
|
-
/**
|
|
8
|
-
* 定义 Store 插件
|
|
9
|
-
*
|
|
10
|
-
* 提供类型安全的插件定义方式
|
|
11
|
-
*
|
|
12
|
-
* @template Options - 插件选项类型
|
|
13
|
-
* @param options - 插件定义选项
|
|
14
|
-
* @returns 插件实例
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // 定义一个简单的日志插件
|
|
19
|
-
* const loggerPlugin = defineStorePlugin({
|
|
20
|
-
* name: 'logger',
|
|
21
|
-
* version: '1.0.0',
|
|
22
|
-
* install(context) {
|
|
23
|
-
* console.log('Logger plugin installed')
|
|
24
|
-
* },
|
|
25
|
-
* onStateChange(storeId, state, oldState) {
|
|
26
|
-
* console.log(`[${storeId}] State changed:`, state)
|
|
27
|
-
* },
|
|
28
|
-
* })
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function defineStorePlugin<Options = Record<string, unknown>>(options: DefinePluginOptions<Options>): StorePlugin<Options>;
|
|
32
|
-
/**
|
|
33
|
-
* 创建插件工厂函数
|
|
34
|
-
*
|
|
35
|
-
* 用于创建可配置的插件
|
|
36
|
-
*
|
|
37
|
-
* @template Options - 插件选项类型
|
|
38
|
-
* @param factory - 插件工厂函数
|
|
39
|
-
* @returns 插件工厂
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // 创建可配置的持久化插件
|
|
44
|
-
* const createPersistPlugin = createPluginFactory<{ key: string }>(
|
|
45
|
-
* (options) => ({
|
|
46
|
-
* name: 'persist',
|
|
47
|
-
* install(context) {
|
|
48
|
-
* console.log('Persist key:', options?.key)
|
|
49
|
-
* },
|
|
50
|
-
* })
|
|
51
|
-
* )
|
|
52
|
-
*
|
|
53
|
-
* // 使用
|
|
54
|
-
* const plugin = createPersistPlugin({ key: 'my-store' })
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare function createPluginFactory<Options = Record<string, unknown>>(factory: (options?: Options) => DefinePluginOptions<Options>): PluginFactory<Options>;
|
|
58
|
-
/**
|
|
59
|
-
* 组合多个插件
|
|
60
|
-
*
|
|
61
|
-
* @param plugins - 插件列表
|
|
62
|
-
* @returns 组合后的插件
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const combinedPlugin = composePlugins([
|
|
67
|
-
* loggerPlugin,
|
|
68
|
-
* persistPlugin,
|
|
69
|
-
* devtoolsPlugin,
|
|
70
|
-
* ])
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export declare function composePlugins(plugins: StorePlugin[]): StorePlugin;
|
|
74
|
-
//# sourceMappingURL=define-plugin.d.ts.map
|
package/lib/plugins/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件模块导出
|
|
3
|
-
*
|
|
4
|
-
* @module plugins
|
|
5
|
-
*/
|
|
6
|
-
export { composePlugins, createPluginFactory, defineStorePlugin, } from './define-plugin';
|
|
7
|
-
export { createPluginManager, getGlobalPluginManager, setGlobalPluginManager, } from './plugin-manager';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件管理器
|
|
3
|
-
*
|
|
4
|
-
* @module plugins/plugin-manager
|
|
5
|
-
*/
|
|
6
|
-
import type { PluginManager } from '../types';
|
|
7
|
-
/**
|
|
8
|
-
* 创建插件管理器
|
|
9
|
-
*
|
|
10
|
-
* @returns 插件管理器实例
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const manager = createPluginManager()
|
|
15
|
-
*
|
|
16
|
-
* // 注册插件
|
|
17
|
-
* manager.use(myPlugin, { option: 'value' })
|
|
18
|
-
*
|
|
19
|
-
* // 获取插件
|
|
20
|
-
* const plugin = manager.get('my-plugin')
|
|
21
|
-
*
|
|
22
|
-
* // 移除插件
|
|
23
|
-
* manager.remove('my-plugin')
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function createPluginManager(): PluginManager;
|
|
27
|
-
/**
|
|
28
|
-
* 获取全局插件管理器
|
|
29
|
-
*/
|
|
30
|
-
export declare function getGlobalPluginManager(): PluginManager;
|
|
31
|
-
/**
|
|
32
|
-
* 设置全局插件管理器
|
|
33
|
-
*/
|
|
34
|
-
export declare function setGlobalPluginManager(manager: PluginManager): void;
|
|
35
|
-
//# sourceMappingURL=plugin-manager.d.ts.map
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @lkit/store-core 类型定义
|
|
3
|
-
*
|
|
4
|
-
* 提供状态管理的核心类型定义
|
|
5
|
-
* @module types
|
|
6
|
-
*/
|
|
7
|
-
export * from './store';
|
|
8
|
-
export * from './plugin';
|
|
9
|
-
export * from './middleware';
|
|
10
|
-
export * from './subscription';
|
|
11
|
-
export * from './utility';
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 防抖和节流工具函数
|
|
3
|
-
*
|
|
4
|
-
* 提供性能优化的防抖、节流功能
|
|
5
|
-
* @module utils/debounce-throttle
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* 防抖函数返回类型
|
|
9
|
-
*/
|
|
10
|
-
export interface DebouncedFunction<T extends (...args: never[]) => void> {
|
|
11
|
-
(...args: Parameters<T>): void;
|
|
12
|
-
/** 取消待执行的调用 */
|
|
13
|
-
cancel: () => void;
|
|
14
|
-
/** 立即执行待处理的调用 */
|
|
15
|
-
flush: () => void;
|
|
16
|
-
/** 是否有待处理的调用 */
|
|
17
|
-
pending: () => boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 节流函数返回类型
|
|
21
|
-
*/
|
|
22
|
-
export interface ThrottledFunction<T extends (...args: never[]) => void> {
|
|
23
|
-
(...args: Parameters<T>): void;
|
|
24
|
-
/** 取消待执行的调用 */
|
|
25
|
-
cancel: () => void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 创建防抖函数
|
|
29
|
-
*
|
|
30
|
-
* 在连续调用停止后,延迟指定时间执行函数
|
|
31
|
-
*
|
|
32
|
-
* @template T - 函数类型
|
|
33
|
-
* @param fn - 需要防抖的函数
|
|
34
|
-
* @param delay - 延迟时间(毫秒)
|
|
35
|
-
* @param immediate - 是否在首次调用时立即执行
|
|
36
|
-
* @returns 防抖后的函数
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const debouncedSearch = debounce((query: string) => {
|
|
41
|
-
* fetchResults(query)
|
|
42
|
-
* }, 300)
|
|
43
|
-
*
|
|
44
|
-
* // 连续调用只会在最后一次调用后 300ms 执行
|
|
45
|
-
* debouncedSearch('a')
|
|
46
|
-
* debouncedSearch('ab')
|
|
47
|
-
* debouncedSearch('abc') // 只有这次会触发
|
|
48
|
-
*
|
|
49
|
-
* // 取消待执行的调用
|
|
50
|
-
* debouncedSearch.cancel()
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare function debounce<T extends (...args: never[]) => void>(fn: T, delay: number, immediate?: boolean): DebouncedFunction<T>;
|
|
54
|
-
/**
|
|
55
|
-
* 创建节流函数
|
|
56
|
-
*
|
|
57
|
-
* 在指定时间间隔内最多执行一次函数
|
|
58
|
-
*
|
|
59
|
-
* @template T - 函数类型
|
|
60
|
-
* @param fn - 需要节流的函数
|
|
61
|
-
* @param interval - 间隔时间(毫秒)
|
|
62
|
-
* @param options - 节流选项
|
|
63
|
-
* @param options.leading - 是否在时间窗开始时立即执行
|
|
64
|
-
* @param options.trailing - 是否在时间窗结束时补执行最后一次调用
|
|
65
|
-
* @returns 节流后的函数
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const throttledUpdate = throttle((x: number, y: number) => {
|
|
70
|
-
* updatePosition(x, y)
|
|
71
|
-
* }, 100)
|
|
72
|
-
*
|
|
73
|
-
* // 在 100ms 内多次调用,只会执行一次
|
|
74
|
-
* window.addEventListener('mousemove', (e) => {
|
|
75
|
-
* throttledUpdate(e.clientX, e.clientY)
|
|
76
|
-
* })
|
|
77
|
-
*
|
|
78
|
-
* // 取消
|
|
79
|
-
* throttledUpdate.cancel()
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare function throttle<T extends (...args: never[]) => void>(fn: T, interval: number, options?: {
|
|
83
|
-
leading?: boolean;
|
|
84
|
-
trailing?: boolean;
|
|
85
|
-
}): ThrottledFunction<T>;
|
|
86
|
-
//# sourceMappingURL=debounce-throttle.d.ts.map
|