@the-w1zard/the-cloud 1.0.2 → 1.0.3
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/dist/index.js +25850 -8
- package/package.json +12 -3
- package/src/the-cloud.d.ts +0 -0
- package/dist/hooks/callback.d.ts +0 -1
- package/dist/hooks/callback.js +0 -13
- package/dist/hooks/compose-event-handlers.d.ts +0 -10
- package/dist/hooks/compose-event-handlers.js +0 -10
- package/dist/hooks/core/index.d.ts +0 -1
- package/dist/hooks/core/index.js +0 -1
- package/dist/hooks/core/use-id.d.ts +0 -1
- package/dist/hooks/core/use-id.js +0 -4
- package/dist/hooks/core/use-reducer.d.ts +0 -1
- package/dist/hooks/core/use-reducer.js +0 -14
- package/dist/hooks/core/use-ref.d.ts +0 -92
- package/dist/hooks/core/use-ref.js +0 -559
- package/dist/hooks/core/use-state2.d.ts +0 -1
- package/dist/hooks/core/use-state2.js +0 -15
- package/dist/hooks/deferred_value.d.ts +0 -1
- package/dist/hooks/deferred_value.js +0 -12
- package/dist/hooks/effect.d.ts +0 -1
- package/dist/hooks/effect.js +0 -37
- package/dist/hooks/hooks.d.ts +0 -1
- package/dist/hooks/hooks.js +0 -1
- package/dist/hooks/impertaive_handle.d.ts +0 -3
- package/dist/hooks/impertaive_handle.js +0 -24
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -4
- package/dist/hooks/init_hooks.d.ts +0 -285
- package/dist/hooks/init_hooks.js +0 -285
- package/dist/hooks/lazy.d.ts +0 -3
- package/dist/hooks/lazy.js +0 -15
- package/dist/hooks/memo.d.ts +0 -2
- package/dist/hooks/memo.js +0 -44
- package/dist/hooks/rect.d.ts +0 -24
- package/dist/hooks/rect.js +0 -77
- package/dist/hooks/state.d.ts +0 -1
- package/dist/hooks/state.js +0 -34
- package/dist/hooks/suspense.d.ts +0 -4
- package/dist/hooks/suspense.js +0 -10
- package/dist/hooks/types.d.ts +0 -25
- package/dist/hooks/types.js +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/the-cloud.d.ts +0 -406
- package/dist/the-cloud.js +0 -1386
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
/**
|
|
3
|
-
* // ⣄ useState
|
|
4
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
5
|
-
type StateOptions<T, S = T> = {
|
|
6
|
-
equals?: (a: S, b: S) => boolean;
|
|
7
|
-
selector?: ((value: T) => S) | null;
|
|
8
|
-
derive?: ((value: T) => any) | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type HookSlot = {
|
|
12
|
-
value: any;
|
|
13
|
-
deps?: any[];
|
|
14
|
-
cleanup?: (() => void) | null;
|
|
15
|
-
callback?: (...args: any[]) => any;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
let hookIndex = 0;
|
|
19
|
-
const hookStore: HookSlot[] = [];
|
|
20
|
-
|
|
21
|
-
export function resetHookIndex() {
|
|
22
|
-
hookIndex = 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function useState<T, S = T>(
|
|
26
|
-
initialValue?: T | (() => T),
|
|
27
|
-
options: StateOptions<T, S> = {},
|
|
28
|
-
) {
|
|
29
|
-
const i = hookIndex++;
|
|
30
|
-
let slot = hookStore[i];
|
|
31
|
-
|
|
32
|
-
if (!slot) {
|
|
33
|
-
const value = typeof initialValue === 'function'
|
|
34
|
-
? (initialValue as () => T)()
|
|
35
|
-
: initialValue as T;
|
|
36
|
-
|
|
37
|
-
slot = {
|
|
38
|
-
value: {
|
|
39
|
-
current: value,
|
|
40
|
-
derived: options.derive ? options.derive(value) : undefined,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
hookStore[i] = slot;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const s = slot.value as { current: T; derived: any };
|
|
47
|
-
const equals = options.equals ?? ((a: S, b: S) => a === b);
|
|
48
|
-
const selector = options.selector ?? null;
|
|
49
|
-
const derive = options.derive ?? null;
|
|
50
|
-
|
|
51
|
-
const getValue = (): S =>
|
|
52
|
-
selector ? selector(s.current) : s.current as unknown as S;
|
|
53
|
-
|
|
54
|
-
const setValue = (v: T | ((prev: T) => T)) => {
|
|
55
|
-
const next = typeof v === 'function'
|
|
56
|
-
? (v as (prev: T) => T)(s.current)
|
|
57
|
-
: v;
|
|
58
|
-
|
|
59
|
-
const prevSelected = getValue();
|
|
60
|
-
const nextSelected = selector
|
|
61
|
-
? selector(next)
|
|
62
|
-
: next as unknown as S;
|
|
63
|
-
|
|
64
|
-
if (!equals(prevSelected, nextSelected)) {
|
|
65
|
-
s.current = next;
|
|
66
|
-
if (derive) s.derived = derive(next);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return next;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
if (derive) return [getValue(), setValue, s.derived] as const;
|
|
73
|
-
return [getValue(), setValue] as const;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// #endregion
|
|
77
|
-
// ⣄ useCallback
|
|
78
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
79
|
-
export function useCallback<T extends (...args: any[]) => any>( callback: T, deps?: any[], __sauron_id__?: string,): T {
|
|
80
|
-
const i = hookIndex++;
|
|
81
|
-
let slot = hookStore[i];
|
|
82
|
-
|
|
83
|
-
if (!slot) {
|
|
84
|
-
slot = { value: undefined, callback, deps: deps ?? [] };
|
|
85
|
-
hookStore[i] = slot;
|
|
86
|
-
return callback;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const changed = !deps ||
|
|
90
|
-
!slot.deps ||
|
|
91
|
-
deps.length !== slot.deps.length ||
|
|
92
|
-
deps.some((d, j) => !Object.is(d, slot!.deps![j]));
|
|
93
|
-
|
|
94
|
-
if (changed) {
|
|
95
|
-
slot.callback = callback;
|
|
96
|
-
slot.deps = deps ?? [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return slot.callback as T;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// #endregion
|
|
103
|
-
// ⣄ useEffect
|
|
104
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
105
|
-
export function useEffect(
|
|
106
|
-
effect: (signal?: AbortSignal) => void | (() => void),
|
|
107
|
-
deps?: any[],
|
|
108
|
-
__sauron_id__?: string,
|
|
109
|
-
): void {
|
|
110
|
-
const i = hookIndex++;
|
|
111
|
-
let slot = hookStore[i];
|
|
112
|
-
|
|
113
|
-
const run = () => {
|
|
114
|
-
const controller = new AbortController();
|
|
115
|
-
const cleanup = effect(controller.signal);
|
|
116
|
-
|
|
117
|
-
return () => {
|
|
118
|
-
controller.abort();
|
|
119
|
-
if (typeof cleanup === 'function') cleanup();
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
if (!slot) {
|
|
124
|
-
slot = {
|
|
125
|
-
value: undefined,
|
|
126
|
-
deps: deps ? [...deps] : undefined,
|
|
127
|
-
cleanup: run(),
|
|
128
|
-
};
|
|
129
|
-
hookStore[i] = slot;
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const changed = deps === undefined ||
|
|
134
|
-
slot.deps === undefined ||
|
|
135
|
-
deps.length !== slot.deps.length ||
|
|
136
|
-
deps.some((d, j) => !Object.is(d, slot!.deps![j]));
|
|
137
|
-
|
|
138
|
-
if (changed) {
|
|
139
|
-
slot.cleanup?.();
|
|
140
|
-
slot.deps = deps ? [...deps] : undefined;
|
|
141
|
-
slot.cleanup = run();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// #endregion
|
|
145
|
-
// ⣄ useCell
|
|
146
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
147
|
-
const cellStore = new Map<string, any>();
|
|
148
|
-
export function useCell<T=A>(v: A, k: A = `${se._sid()}_USECELL`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
149
|
-
const cellKey = `${k}:${s}:${m}:${r}`;
|
|
150
|
-
|
|
151
|
-
// Initialize local state if not present
|
|
152
|
-
if (!cellStore.has(cellKey)) {
|
|
153
|
-
const initial = typeof v === "function" ? (v as Function)() : v;
|
|
154
|
-
cellStore.set(cellKey, initial);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const currentState = cellStore.get(cellKey);
|
|
158
|
-
|
|
159
|
-
// Mock local setter that mimics setLive behavior
|
|
160
|
-
const setLive = (next: any) => {
|
|
161
|
-
const current = cellStore.get(cellKey);
|
|
162
|
-
const newValue = typeof next === "function" ? next(current) : next;
|
|
163
|
-
cellStore.set(cellKey, newValue);
|
|
164
|
-
return newValue;
|
|
165
|
-
};
|
|
166
|
-
return [currentState as T, setLive] as const;
|
|
167
|
-
}
|
|
168
|
-
// #endregion
|
|
169
|
-
// ⣄ cell
|
|
170
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
171
|
-
export function cell<T = any>(v: A,k: A = `${se._sid()}_USECELL`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
172
|
-
const cellKey = `${k}:${s}:${m}:${r}`;
|
|
173
|
-
|
|
174
|
-
// Initialize if not already present in the fallback store
|
|
175
|
-
if (!cellStore.has(cellKey)) {
|
|
176
|
-
const initial = typeof v === "function" ? (v as Function)() : v;
|
|
177
|
-
cellStore.set(cellKey, initial);
|
|
178
|
-
}
|
|
179
|
-
const currentState = cellStore.get(cellKey);
|
|
180
|
-
// Matches your MCR_Com bo return structure (read-only, no setter)
|
|
181
|
-
return currentState as T
|
|
182
|
-
}
|
|
183
|
-
// #endregion
|
|
184
|
-
// ⣄ atom
|
|
185
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
186
|
-
const refStore = new Map<string, { current: any }>();
|
|
187
|
-
export function atom<T = any>( v: A, k: A = `__THE_WARLOCK_SIGNALS_${se._sid()}`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
188
|
-
const rk = `${k}:${s}:${m}:${r}`;
|
|
189
|
-
if (!refStore.has(rk)) refStore.set(rk, { current: typeof v === 'function' ? (v as Function)() : v });
|
|
190
|
-
const ref = refStore.get(rk)!;
|
|
191
|
-
return {
|
|
192
|
-
get value(): T { return ref.current },
|
|
193
|
-
set value(v: T) { ref.current = v },
|
|
194
|
-
peek(): T { return ref.current },
|
|
195
|
-
get current(): T { return ref.current },
|
|
196
|
-
set current(v: T) { ref.current = v },
|
|
197
|
-
set crt(v: T) { ref.current = v },
|
|
198
|
-
set set(v: T) { ref.current = v },
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
// #endregion
|
|
202
|
-
// ⣄ useSXX
|
|
203
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
204
|
-
export function resetEffectIndex() {
|
|
205
|
-
effectIndex = 0;
|
|
206
|
-
}
|
|
207
|
-
export function useSXX(initialValue: any) {
|
|
208
|
-
let state = initialValue;
|
|
209
|
-
const listeners = new Set();
|
|
210
|
-
|
|
211
|
-
const getState = () => state;
|
|
212
|
-
|
|
213
|
-
const setState = (newValue: any) => {
|
|
214
|
-
const nextValue =
|
|
215
|
-
typeof newValue === 'function' ? newValue(state) : newValue;
|
|
216
|
-
|
|
217
|
-
if (Object.is(state, nextValue)) return;
|
|
218
|
-
|
|
219
|
-
state = nextValue;
|
|
220
|
-
listeners.forEach((listener: any) => listener(state));
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const subscribe = (listener: any) => {
|
|
224
|
-
listeners.add(listener);
|
|
225
|
-
return () => listeners.delete(listener);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
return [getState, setState, subscribe];
|
|
229
|
-
}
|
|
230
|
-
// #endregion
|
|
231
|
-
// ⣄ useEFFEX
|
|
232
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
233
|
-
let effectIndex = 0;
|
|
234
|
-
const effectStore: any = [];
|
|
235
|
-
|
|
236
|
-
export function useEFFEX(effect: any, deps: any) {
|
|
237
|
-
const i = effectIndex++;
|
|
238
|
-
const prev = effectStore[i];
|
|
239
|
-
|
|
240
|
-
const hasDeps = Array.isArray(deps);
|
|
241
|
-
const changed =
|
|
242
|
-
!hasDeps ||
|
|
243
|
-
!prev ||
|
|
244
|
-
!prev.deps ||
|
|
245
|
-
deps.length !== prev.deps.length ||
|
|
246
|
-
deps.some((dep, j) => !Object.is(dep, prev.deps[j]));
|
|
247
|
-
|
|
248
|
-
if (changed) {
|
|
249
|
-
// cleanup previous
|
|
250
|
-
if (prev && typeof prev.cleanup === 'function') {
|
|
251
|
-
prev.cleanup();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const cleanup = effect();
|
|
255
|
-
effectStore[i] = {
|
|
256
|
-
deps: hasDeps ? deps : null,
|
|
257
|
-
cleanup: typeof cleanup === 'function' ? cleanup : null,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// #endregion
|
|
263
|
-
// ⣄ atom
|
|
264
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
// #endregion
|
|
269
|
-
// ⣄ atom
|
|
270
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
// #endregion
|
|
276
|
-
// ⣄ atom
|
|
277
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// #endregion
|
|
283
|
-
// ⣄ atom
|
|
284
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
285
|
-
*/
|
package/dist/hooks/init_hooks.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
/**
|
|
3
|
-
* // ⣄ useState
|
|
4
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
5
|
-
type StateOptions<T, S = T> = {
|
|
6
|
-
equals?: (a: S, b: S) => boolean;
|
|
7
|
-
selector?: ((value: T) => S) | null;
|
|
8
|
-
derive?: ((value: T) => any) | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type HookSlot = {
|
|
12
|
-
value: any;
|
|
13
|
-
deps?: any[];
|
|
14
|
-
cleanup?: (() => void) | null;
|
|
15
|
-
callback?: (...args: any[]) => any;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
let hookIndex = 0;
|
|
19
|
-
const hookStore: HookSlot[] = [];
|
|
20
|
-
|
|
21
|
-
export function resetHookIndex() {
|
|
22
|
-
hookIndex = 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function useState<T, S = T>(
|
|
26
|
-
initialValue?: T | (() => T),
|
|
27
|
-
options: StateOptions<T, S> = {},
|
|
28
|
-
) {
|
|
29
|
-
const i = hookIndex++;
|
|
30
|
-
let slot = hookStore[i];
|
|
31
|
-
|
|
32
|
-
if (!slot) {
|
|
33
|
-
const value = typeof initialValue === 'function'
|
|
34
|
-
? (initialValue as () => T)()
|
|
35
|
-
: initialValue as T;
|
|
36
|
-
|
|
37
|
-
slot = {
|
|
38
|
-
value: {
|
|
39
|
-
current: value,
|
|
40
|
-
derived: options.derive ? options.derive(value) : undefined,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
hookStore[i] = slot;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const s = slot.value as { current: T; derived: any };
|
|
47
|
-
const equals = options.equals ?? ((a: S, b: S) => a === b);
|
|
48
|
-
const selector = options.selector ?? null;
|
|
49
|
-
const derive = options.derive ?? null;
|
|
50
|
-
|
|
51
|
-
const getValue = (): S =>
|
|
52
|
-
selector ? selector(s.current) : s.current as unknown as S;
|
|
53
|
-
|
|
54
|
-
const setValue = (v: T | ((prev: T) => T)) => {
|
|
55
|
-
const next = typeof v === 'function'
|
|
56
|
-
? (v as (prev: T) => T)(s.current)
|
|
57
|
-
: v;
|
|
58
|
-
|
|
59
|
-
const prevSelected = getValue();
|
|
60
|
-
const nextSelected = selector
|
|
61
|
-
? selector(next)
|
|
62
|
-
: next as unknown as S;
|
|
63
|
-
|
|
64
|
-
if (!equals(prevSelected, nextSelected)) {
|
|
65
|
-
s.current = next;
|
|
66
|
-
if (derive) s.derived = derive(next);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return next;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
if (derive) return [getValue(), setValue, s.derived] as const;
|
|
73
|
-
return [getValue(), setValue] as const;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// #endregion
|
|
77
|
-
// ⣄ useCallback
|
|
78
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
79
|
-
export function useCallback<T extends (...args: any[]) => any>( callback: T, deps?: any[], __sauron_id__?: string,): T {
|
|
80
|
-
const i = hookIndex++;
|
|
81
|
-
let slot = hookStore[i];
|
|
82
|
-
|
|
83
|
-
if (!slot) {
|
|
84
|
-
slot = { value: undefined, callback, deps: deps ?? [] };
|
|
85
|
-
hookStore[i] = slot;
|
|
86
|
-
return callback;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const changed = !deps ||
|
|
90
|
-
!slot.deps ||
|
|
91
|
-
deps.length !== slot.deps.length ||
|
|
92
|
-
deps.some((d, j) => !Object.is(d, slot!.deps![j]));
|
|
93
|
-
|
|
94
|
-
if (changed) {
|
|
95
|
-
slot.callback = callback;
|
|
96
|
-
slot.deps = deps ?? [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return slot.callback as T;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// #endregion
|
|
103
|
-
// ⣄ useEffect
|
|
104
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
105
|
-
export function useEffect(
|
|
106
|
-
effect: (signal?: AbortSignal) => void | (() => void),
|
|
107
|
-
deps?: any[],
|
|
108
|
-
__sauron_id__?: string,
|
|
109
|
-
): void {
|
|
110
|
-
const i = hookIndex++;
|
|
111
|
-
let slot = hookStore[i];
|
|
112
|
-
|
|
113
|
-
const run = () => {
|
|
114
|
-
const controller = new AbortController();
|
|
115
|
-
const cleanup = effect(controller.signal);
|
|
116
|
-
|
|
117
|
-
return () => {
|
|
118
|
-
controller.abort();
|
|
119
|
-
if (typeof cleanup === 'function') cleanup();
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
if (!slot) {
|
|
124
|
-
slot = {
|
|
125
|
-
value: undefined,
|
|
126
|
-
deps: deps ? [...deps] : undefined,
|
|
127
|
-
cleanup: run(),
|
|
128
|
-
};
|
|
129
|
-
hookStore[i] = slot;
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const changed = deps === undefined ||
|
|
134
|
-
slot.deps === undefined ||
|
|
135
|
-
deps.length !== slot.deps.length ||
|
|
136
|
-
deps.some((d, j) => !Object.is(d, slot!.deps![j]));
|
|
137
|
-
|
|
138
|
-
if (changed) {
|
|
139
|
-
slot.cleanup?.();
|
|
140
|
-
slot.deps = deps ? [...deps] : undefined;
|
|
141
|
-
slot.cleanup = run();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// #endregion
|
|
145
|
-
// ⣄ useCell
|
|
146
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
147
|
-
const cellStore = new Map<string, any>();
|
|
148
|
-
export function useCell<T=A>(v: A, k: A = `${se._sid()}_USECELL`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
149
|
-
const cellKey = `${k}:${s}:${m}:${r}`;
|
|
150
|
-
|
|
151
|
-
// Initialize local state if not present
|
|
152
|
-
if (!cellStore.has(cellKey)) {
|
|
153
|
-
const initial = typeof v === "function" ? (v as Function)() : v;
|
|
154
|
-
cellStore.set(cellKey, initial);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const currentState = cellStore.get(cellKey);
|
|
158
|
-
|
|
159
|
-
// Mock local setter that mimics setLive behavior
|
|
160
|
-
const setLive = (next: any) => {
|
|
161
|
-
const current = cellStore.get(cellKey);
|
|
162
|
-
const newValue = typeof next === "function" ? next(current) : next;
|
|
163
|
-
cellStore.set(cellKey, newValue);
|
|
164
|
-
return newValue;
|
|
165
|
-
};
|
|
166
|
-
return [currentState as T, setLive] as const;
|
|
167
|
-
}
|
|
168
|
-
// #endregion
|
|
169
|
-
// ⣄ cell
|
|
170
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
171
|
-
export function cell<T = any>(v: A,k: A = `${se._sid()}_USECELL`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
172
|
-
const cellKey = `${k}:${s}:${m}:${r}`;
|
|
173
|
-
|
|
174
|
-
// Initialize if not already present in the fallback store
|
|
175
|
-
if (!cellStore.has(cellKey)) {
|
|
176
|
-
const initial = typeof v === "function" ? (v as Function)() : v;
|
|
177
|
-
cellStore.set(cellKey, initial);
|
|
178
|
-
}
|
|
179
|
-
const currentState = cellStore.get(cellKey);
|
|
180
|
-
// Matches your MCR_Com bo return structure (read-only, no setter)
|
|
181
|
-
return currentState as T
|
|
182
|
-
}
|
|
183
|
-
// #endregion
|
|
184
|
-
// ⣄ atom
|
|
185
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
186
|
-
const refStore = new Map<string, { current: any }>();
|
|
187
|
-
export function atom<T = any>( v: A, k: A = `__THE_WARLOCK_SIGNALS_${se._sid()}`, s: S = ssr.s, m: S = ssr.m, r: S = ssr.s) {
|
|
188
|
-
const rk = `${k}:${s}:${m}:${r}`;
|
|
189
|
-
if (!refStore.has(rk)) refStore.set(rk, { current: typeof v === 'function' ? (v as Function)() : v });
|
|
190
|
-
const ref = refStore.get(rk)!;
|
|
191
|
-
return {
|
|
192
|
-
get value(): T { return ref.current },
|
|
193
|
-
set value(v: T) { ref.current = v },
|
|
194
|
-
peek(): T { return ref.current },
|
|
195
|
-
get current(): T { return ref.current },
|
|
196
|
-
set current(v: T) { ref.current = v },
|
|
197
|
-
set crt(v: T) { ref.current = v },
|
|
198
|
-
set set(v: T) { ref.current = v },
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
// #endregion
|
|
202
|
-
// ⣄ useSXX
|
|
203
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
204
|
-
export function resetEffectIndex() {
|
|
205
|
-
effectIndex = 0;
|
|
206
|
-
}
|
|
207
|
-
export function useSXX(initialValue: any) {
|
|
208
|
-
let state = initialValue;
|
|
209
|
-
const listeners = new Set();
|
|
210
|
-
|
|
211
|
-
const getState = () => state;
|
|
212
|
-
|
|
213
|
-
const setState = (newValue: any) => {
|
|
214
|
-
const nextValue =
|
|
215
|
-
typeof newValue === 'function' ? newValue(state) : newValue;
|
|
216
|
-
|
|
217
|
-
if (Object.is(state, nextValue)) return;
|
|
218
|
-
|
|
219
|
-
state = nextValue;
|
|
220
|
-
listeners.forEach((listener: any) => listener(state));
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const subscribe = (listener: any) => {
|
|
224
|
-
listeners.add(listener);
|
|
225
|
-
return () => listeners.delete(listener);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
return [getState, setState, subscribe];
|
|
229
|
-
}
|
|
230
|
-
// #endregion
|
|
231
|
-
// ⣄ useEFFEX
|
|
232
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
233
|
-
let effectIndex = 0;
|
|
234
|
-
const effectStore: any = [];
|
|
235
|
-
|
|
236
|
-
export function useEFFEX(effect: any, deps: any) {
|
|
237
|
-
const i = effectIndex++;
|
|
238
|
-
const prev = effectStore[i];
|
|
239
|
-
|
|
240
|
-
const hasDeps = Array.isArray(deps);
|
|
241
|
-
const changed =
|
|
242
|
-
!hasDeps ||
|
|
243
|
-
!prev ||
|
|
244
|
-
!prev.deps ||
|
|
245
|
-
deps.length !== prev.deps.length ||
|
|
246
|
-
deps.some((dep, j) => !Object.is(dep, prev.deps[j]));
|
|
247
|
-
|
|
248
|
-
if (changed) {
|
|
249
|
-
// cleanup previous
|
|
250
|
-
if (prev && typeof prev.cleanup === 'function') {
|
|
251
|
-
prev.cleanup();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const cleanup = effect();
|
|
255
|
-
effectStore[i] = {
|
|
256
|
-
deps: hasDeps ? deps : null,
|
|
257
|
-
cleanup: typeof cleanup === 'function' ? cleanup : null,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// #endregion
|
|
263
|
-
// ⣄ atom
|
|
264
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
// #endregion
|
|
269
|
-
// ⣄ atom
|
|
270
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
// #endregion
|
|
276
|
-
// ⣄ atom
|
|
277
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// #endregion
|
|
283
|
-
// ⣄ atom
|
|
284
|
-
// #region ═════════════════════════════════════════════════════════════════════════════════════════════════
|
|
285
|
-
*/
|
package/dist/hooks/lazy.d.ts
DELETED
package/dist/hooks/lazy.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function lazy(load) {
|
|
2
|
-
let _mod = null;
|
|
3
|
-
let _error = null;
|
|
4
|
-
let _promise = null;
|
|
5
|
-
return (props) => {
|
|
6
|
-
if (_error)
|
|
7
|
-
throw _error;
|
|
8
|
-
if (_mod)
|
|
9
|
-
return _mod.default(props);
|
|
10
|
-
if (!_promise) {
|
|
11
|
-
_promise = load().then(m => { _mod = m; }).catch(e => { _error = e; });
|
|
12
|
-
}
|
|
13
|
-
throw _promise;
|
|
14
|
-
};
|
|
15
|
-
}
|
package/dist/hooks/memo.d.ts
DELETED
package/dist/hooks/memo.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
function _depsEqual(a, b) {
|
|
2
|
-
if (a.length !== b.length)
|
|
3
|
-
return false;
|
|
4
|
-
for (let i = 0; i < a.length; i++) {
|
|
5
|
-
if (!Object.is(a[i], b[i]))
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
export function useMemo(factory, deps, __sauron_id__ = _sid()) {
|
|
11
|
-
return createHook('useMemo', __sauron_id__, () => ({ value: factory(), deps }), (state) => {
|
|
12
|
-
if (!_depsEqual(state.deps ?? [], deps)) {
|
|
13
|
-
state.value = factory();
|
|
14
|
-
state.deps = deps;
|
|
15
|
-
}
|
|
16
|
-
return state.value;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export function memo(component, compare) {
|
|
20
|
-
let lastProps = null;
|
|
21
|
-
let lastResult = null;
|
|
22
|
-
return (props) => {
|
|
23
|
-
if (lastProps !== null) {
|
|
24
|
-
const equal = compare
|
|
25
|
-
? compare(lastProps, props)
|
|
26
|
-
: _shallowEqual(lastProps, props);
|
|
27
|
-
if (equal)
|
|
28
|
-
return lastResult;
|
|
29
|
-
}
|
|
30
|
-
lastProps = props;
|
|
31
|
-
lastResult = component(props);
|
|
32
|
-
return lastResult;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function _shallowEqual(a, b) {
|
|
36
|
-
const ka = Object.keys(a);
|
|
37
|
-
const kb = Object.keys(b);
|
|
38
|
-
if (ka.length !== kb.length)
|
|
39
|
-
return false;
|
|
40
|
-
for (const k of ka)
|
|
41
|
-
if (!Object.is(a[k], b[k]))
|
|
42
|
-
return false;
|
|
43
|
-
return true;
|
|
44
|
-
}
|
package/dist/hooks/rect.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type Measurable = {
|
|
2
|
-
getBoundingClientRect(): DOMRect;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* Observes an element's rectangle on screen (getBoundingClientRect)
|
|
6
|
-
* This is useful to track elements on the screen and attach other elements
|
|
7
|
-
* that might be in different layers, etc.
|
|
8
|
-
*/
|
|
9
|
-
export declare function observeElementRect(
|
|
10
|
-
/** The element whose rect to observe */
|
|
11
|
-
elementToObserve: Measurable,
|
|
12
|
-
/** The callback which will be called when the rect changes */
|
|
13
|
-
callback: CallbackFn): () => void;
|
|
14
|
-
export type CallbackFn = (rect: DOMRect) => void;
|
|
15
|
-
export type ObservedData = {
|
|
16
|
-
rect: DOMRect;
|
|
17
|
-
callbacks: Array<CallbackFn>;
|
|
18
|
-
};
|
|
19
|
-
export declare const observedElements: Map<Measurable, ObservedData>;
|
|
20
|
-
export declare function runLoop(): void;
|
|
21
|
-
/**
|
|
22
|
-
* Returns whether 2 rects are equal in values
|
|
23
|
-
*/
|
|
24
|
-
export declare function rectEquals(rect1: DOMRect, rect2: DOMRect): boolean;
|