@fukict/flux 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Fukict Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/Flux.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import type { FluxInstance, FluxListener, FluxSelector, Unsubscribe } from './types';
2
+ /**
3
+ * Flux state management class
4
+ *
5
+ * Responsibilities:
6
+ * 1. State storage
7
+ * 2. Subscription management
8
+ * 3. State reading
9
+ * 4. State update interface (called by external Actions)
10
+ */
11
+ export declare class Flux<T> implements FluxInstance<T> {
12
+ /**
13
+ * Current state (internal storage)
14
+ */
15
+ private internalState;
16
+ /**
17
+ * State proxy (readonly, returned to external)
18
+ */
19
+ private stateProxy;
20
+ /**
21
+ * Subscription list
22
+ */
23
+ private subscriptions;
24
+ /**
25
+ * Constructor
26
+ * @param initialState Initial state
27
+ */
28
+ constructor(initialState: T);
29
+ /**
30
+ * Create readonly proxy
31
+ */
32
+ private createReadonlyProxy;
33
+ /**
34
+ * Get current state snapshot (readonly proxy)
35
+ */
36
+ getState(): T;
37
+ /**
38
+ * Update state
39
+ * @param newState New state (full replacement or partial update)
40
+ */
41
+ setState(newState: Partial<T> | T): void;
42
+ /**
43
+ * Subscribe to state changes
44
+ */
45
+ subscribe(listener: FluxListener<T>): Unsubscribe;
46
+ subscribe<S>(selector: FluxSelector<T, S>, listener: FluxListener<S>): Unsubscribe;
47
+ /**
48
+ * Notify all subscribers
49
+ */
50
+ private notify;
51
+ /**
52
+ * Determine if it's a partial update
53
+ */
54
+ private isPartialUpdate;
55
+ /**
56
+ * Shallow compare two values for equality
57
+ */
58
+ private shallowEqual;
59
+ }
60
+ //# sourceMappingURL=Flux.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Flux.d.ts","sourceRoot":"","sources":["../src/Flux.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACZ,MAAM,SAAS,CAAC;AAWjB;;;;;;;;GAQG;AACH,qBAAa,IAAI,CAAC,CAAC,CAAE,YAAW,YAAY,CAAC,CAAC,CAAC;IAC7C;;OAEG;IACH,OAAO,CAAC,aAAa,CAAI;IAEzB;;OAEG;IACH,OAAO,CAAC,UAAU,CAAI;IAEtB;;OAEG;IACH,OAAO,CAAC,aAAa,CAAwC;IAE7D;;;OAGG;gBACS,YAAY,EAAE,CAAC;IAK3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAiD3B;;OAEG;IACH,QAAQ,IAAI,CAAC;IAIb;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI;IAiBxC;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW;IACjD,SAAS,CAAC,CAAC,EACT,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,WAAW;IAkCd;;OAEG;IACH,OAAO,CAAC,MAAM;IAgBd;;OAEG;IACH,OAAO,CAAC,eAAe;IAQvB;;OAEG;IACH,OAAO,CAAC,YAAY;CAoCrB"}
package/dist/Flux.js ADDED
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Flux state management class
3
+ *
4
+ * Responsibilities:
5
+ * 1. State storage
6
+ * 2. Subscription management
7
+ * 3. State reading
8
+ * 4. State update interface (called by external Actions)
9
+ */
10
+ export class Flux {
11
+ /**
12
+ * Current state (internal storage)
13
+ */
14
+ internalState;
15
+ /**
16
+ * State proxy (readonly, returned to external)
17
+ */
18
+ stateProxy;
19
+ /**
20
+ * Subscription list
21
+ */
22
+ subscriptions = new Set();
23
+ /**
24
+ * Constructor
25
+ * @param initialState Initial state
26
+ */
27
+ constructor(initialState) {
28
+ this.internalState = initialState;
29
+ this.stateProxy = this.createReadonlyProxy(initialState);
30
+ }
31
+ /**
32
+ * Create readonly proxy
33
+ */
34
+ createReadonlyProxy(state) {
35
+ return new Proxy(state, {
36
+ get(target, prop, receiver) {
37
+ const value = Reflect.get(target, prop, receiver);
38
+ // If value is an object, wrap it in readonly proxy too
39
+ if (value !== null && typeof value === 'object') {
40
+ return new Proxy(value, {
41
+ get: (t, p, r) => Reflect.get(t, p, r),
42
+ set: () => {
43
+ if (process.env.NODE_ENV !== 'production') {
44
+ console.warn('[Flux] Direct state mutation is not allowed. Please use setState() method.');
45
+ }
46
+ return false;
47
+ },
48
+ deleteProperty: () => {
49
+ if (process.env.NODE_ENV !== 'production') {
50
+ console.warn('[Flux] Direct state mutation is not allowed. Please use setState() method.');
51
+ }
52
+ return false;
53
+ },
54
+ });
55
+ }
56
+ return value;
57
+ },
58
+ set: () => {
59
+ if (process.env.NODE_ENV !== 'production') {
60
+ console.warn('[Flux] Direct state mutation is not allowed. Please use setState() method.');
61
+ }
62
+ return false;
63
+ },
64
+ deleteProperty: () => {
65
+ if (process.env.NODE_ENV !== 'production') {
66
+ console.warn('[Flux] Direct state mutation is not allowed. Please use setState() method.');
67
+ }
68
+ return false;
69
+ },
70
+ });
71
+ }
72
+ /**
73
+ * Get current state snapshot (readonly proxy)
74
+ */
75
+ getState() {
76
+ return this.stateProxy;
77
+ }
78
+ /**
79
+ * Update state
80
+ * @param newState New state (full replacement or partial update)
81
+ */
82
+ setState(newState) {
83
+ // Determine if it's a full replacement or partial update
84
+ if (this.isPartialUpdate(newState)) {
85
+ // Partial update: shallow merge
86
+ this.internalState = { ...this.internalState, ...newState };
87
+ }
88
+ else {
89
+ // Full replacement
90
+ this.internalState = newState;
91
+ }
92
+ // Update proxy
93
+ this.stateProxy = this.createReadonlyProxy(this.internalState);
94
+ // Notify all subscribers
95
+ this.notify();
96
+ }
97
+ subscribe(selectorOrListener, listener) {
98
+ let subscription;
99
+ // Determine if it's a normal subscription or selector subscription
100
+ if (listener) {
101
+ // Selector subscription
102
+ const selector = selectorOrListener;
103
+ const initialValue = selector(this.internalState);
104
+ subscription = {
105
+ listener,
106
+ selector,
107
+ lastValue: initialValue,
108
+ };
109
+ }
110
+ else {
111
+ // Normal subscription
112
+ subscription = {
113
+ listener: selectorOrListener,
114
+ };
115
+ }
116
+ // Add to subscription list
117
+ this.subscriptions.add(subscription);
118
+ // Return unsubscribe function
119
+ return () => {
120
+ this.subscriptions.delete(subscription);
121
+ };
122
+ }
123
+ /**
124
+ * Notify all subscribers
125
+ */
126
+ notify() {
127
+ for (const subscription of this.subscriptions) {
128
+ if (subscription.selector) {
129
+ // Selector subscription: compare old and new values
130
+ const newValue = subscription.selector(this.internalState);
131
+ if (!this.shallowEqual(subscription.lastValue, newValue)) {
132
+ subscription.lastValue = newValue;
133
+ subscription.listener(newValue);
134
+ }
135
+ }
136
+ else {
137
+ // Normal subscription: notify directly (pass proxy)
138
+ subscription.listener(this.stateProxy);
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * Determine if it's a partial update
144
+ */
145
+ isPartialUpdate(newState) {
146
+ // Simple heuristic:
147
+ // If newState has fewer keys than current state, consider it a partial update
148
+ const newKeys = Object.keys(newState);
149
+ const stateKeys = Object.keys(this.internalState);
150
+ return newKeys.length < stateKeys.length;
151
+ }
152
+ /**
153
+ * Shallow compare two values for equality
154
+ */
155
+ shallowEqual(a, b) {
156
+ // Primitive type comparison
157
+ if (Object.is(a, b)) {
158
+ return true;
159
+ }
160
+ // null/undefined comparison
161
+ if (a == null || b == null) {
162
+ return false;
163
+ }
164
+ // Object shallow comparison
165
+ if (typeof a === 'object' && typeof b === 'object') {
166
+ const keysA = Object.keys(a);
167
+ const keysB = Object.keys(b);
168
+ if (keysA.length !== keysB.length) {
169
+ return false;
170
+ }
171
+ for (const key of keysA) {
172
+ if (!Object.is(a[key], b[key])) {
173
+ return false;
174
+ }
175
+ }
176
+ return true;
177
+ }
178
+ return false;
179
+ }
180
+ }
181
+ //# sourceMappingURL=Flux.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Flux.js","sourceRoot":"","sources":["../src/Flux.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AACH,MAAM,OAAO,IAAI;IACf;;OAEG;IACK,aAAa,CAAI;IAEzB;;OAEG;IACK,UAAU,CAAI;IAEtB;;OAEG;IACK,aAAa,GAA8B,IAAI,GAAG,EAAE,CAAC;IAE7D;;;OAGG;IACH,YAAY,YAAe;QACzB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACK,mBAAmB,CAAC,KAAQ;QAClC,OAAO,IAAI,KAAK,CAAC,KAAe,EAAE;YAChC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;gB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AAC,CAAC,CAAC,CAAC;YAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAE7B,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,IACE,CAAC,MAAM,CAAC,EAAE,CACP,CAA6B,CAAC,GAAG,CAAC,EAClC,CAA6B,CAAC,GAAG,CAAC,CACpC,EACD,CAAC;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import type { CreateFluxConfig, FluxStore } from './types';
2
+ /**
3
+ * Factory function to create Flux Store
4
+ *
5
+ * @param config Configuration object
6
+ * @returns Flux Store object
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const counterStore = createFlux({
11
+ * state: { count: 0 },
12
+ * actions: (flux) => ({
13
+ * increment() {
14
+ * const state = flux.getState();
15
+ * flux.setState({ count: state.count + 1 });
16
+ * }
17
+ * })
18
+ * });
19
+ *
20
+ * // Usage
21
+ * counterStore.actions.increment();
22
+ * counterStore.subscribe((state) => console.log(state.count));
23
+ * ```
24
+ */
25
+ export declare function createFlux<T, A = {}>(config: CreateFluxConfig<T, A>): FluxStore<T, A>;
26
+ //# sourceMappingURL=createFlux.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFlux.d.ts","sourceRoot":"","sources":["../src/createFlux.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,EAClC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAmBjB"}
@@ -0,0 +1,41 @@
1
+ import { Flux } from './Flux';
2
+ /**
3
+ * Factory function to create Flux Store
4
+ *
5
+ * @param config Configuration object
6
+ * @returns Flux Store object
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const counterStore = createFlux({
11
+ * state: { count: 0 },
12
+ * actions: (flux) => ({
13
+ * increment() {
14
+ * const state = flux.getState();
15
+ * flux.setState({ count: state.count + 1 });
16
+ * }
17
+ * })
18
+ * });
19
+ *
20
+ * // Usage
21
+ * counterStore.actions.increment();
22
+ * counterStore.subscribe((state) => console.log(state.count));
23
+ * ```
24
+ */
25
+ export function createFlux(config) {
26
+ // Create Flux instance
27
+ const flux = new Flux(config.state);
28
+ // Create Actions (if provided)
29
+ const actions = (config.actions ? config.actions(flux) : {});
30
+ // Return unified interface
31
+ return {
32
+ flux,
33
+ actions,
34
+ // Shortcut methods: delegate to flux instance
35
+ getState: () => flux.getState(),
36
+ setState: newState => flux.setState(newState),
37
+ // subscribe method - TypeScript will infer the correct overload from FluxStore<T, A>
38
+ subscribe: flux.subscribe.bind(flux),
39
+ };
40
+ }
41
+ //# sourceMappingURL=createFlux.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFlux.js","sourceRoot":"","sources":["../src/createFlux.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,UAAU,CACxB,MAA8B;IAE9B,uBAAuB;IACvB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAEvC,+BAA+B;IAC/B,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAM,CAAC;IAElE,2BAA2B;IAC3B,OAAO;QACL,IAAI;QACJ,OAAO;QAEP,8CAA8C;QAC9C,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;QAC/B,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAE7C,qFAAqF;QACrF,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;KACrC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fukict/flux - Minimal state management library for Fukict framework
3
+ *
4
+ * Core philosophy: Flux itself has no update permission, only provides subscription mechanism.
5
+ */
6
+ export { Flux } from './Flux';
7
+ export { createFlux } from './createFlux';
8
+ export type { FluxListener, FluxSelector, Unsubscribe, CreateFluxConfig, FluxInstance, FluxStore, } from './types';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,GACV,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @fukict/flux - Minimal state management library for Fukict framework
3
+ *
4
+ * Core philosophy: Flux itself has no update permission, only provides subscription mechanism.
5
+ */
6
+ // 导出核心类
7
+ export { Flux } from './Flux';
8
+ // 导出工厂函数
9
+ export { createFlux } from './createFlux';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAQ;AACR,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Flux listener function type
3
+ */
4
+ export type FluxListener<T> = (state: T) => void;
5
+ /**
6
+ * Selector function type
7
+ */
8
+ export type FluxSelector<T, S> = (state: T) => S;
9
+ /**
10
+ * Unsubscribe function type
11
+ */
12
+ export type Unsubscribe = () => void;
13
+ /**
14
+ * createFlux configuration type
15
+ */
16
+ export interface CreateFluxConfig<T, A> {
17
+ /**
18
+ * Initial state
19
+ */
20
+ state: T;
21
+ /**
22
+ * Actions definition (optional)
23
+ */
24
+ actions?: (flux: FluxInstance<T>) => A;
25
+ }
26
+ /**
27
+ * Flux instance interface (internal use)
28
+ */
29
+ export interface FluxInstance<T> {
30
+ getState(): T;
31
+ setState(newState: Partial<T> | T): void;
32
+ subscribe(listener: FluxListener<T>): Unsubscribe;
33
+ subscribe<S>(selector: FluxSelector<T, S>, listener: FluxListener<S>): Unsubscribe;
34
+ }
35
+ /**
36
+ * createFlux return type
37
+ */
38
+ export interface FluxStore<T, A> {
39
+ /**
40
+ * Flux instance
41
+ */
42
+ flux: FluxInstance<T>;
43
+ /**
44
+ * Actions object
45
+ */
46
+ actions: A;
47
+ /**
48
+ * Get current state (shortcut method)
49
+ */
50
+ getState(): T;
51
+ /**
52
+ * Update state (shortcut method)
53
+ */
54
+ setState(newState: Partial<T> | T): void;
55
+ /**
56
+ * Subscribe to state changes (shortcut method)
57
+ */
58
+ subscribe(listener: FluxListener<T>): Unsubscribe;
59
+ subscribe<S>(selector: FluxSelector<T, S>, listener: FluxListener<S>): Unsubscribe;
60
+ }
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,CAA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C,EACT,QAAQ,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,WAAW,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@fukict/flux",
3
+ "version": "0.1.0",
4
+ "description": "Minimal state management library for Fukict framework",
5
+ "keywords": [
6
+ "fukict",
7
+ "flux",
8
+ "state-management",
9
+ "store",
10
+ "reactive"
11
+ ],
12
+ "bugs": {
13
+ "url": "https://github.com/fukict/fukict/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/fukict/fukict.git",
18
+ "directory": "packages/flux"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Fukict Team",
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "browser": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "devDependencies": {
39
+ "typescript": "^5.6.3"
40
+ },
41
+ "engines": {
42
+ "node": ">=16.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsx ../../scripts/build-package.ts --pkg-name flux --no-watch",
46
+ "dev": "tsx ../../scripts/build-package.ts --pkg-name flux --watch",
47
+ "lint": "tsc --noEmit",
48
+ "typecheck": "tsc --noEmit"
49
+ }
50
+ }