atomirx 0.0.8 → 0.1.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 (138) hide show
  1. package/README.md +198 -2234
  2. package/bin/cli.js +90 -0
  3. package/dist/core/derived.d.ts +2 -2
  4. package/dist/core/effect.d.ts +3 -2
  5. package/dist/core/onCreateHook.d.ts +15 -2
  6. package/dist/core/onErrorHook.d.ts +4 -1
  7. package/dist/core/pool.d.ts +78 -0
  8. package/dist/core/pool.test.d.ts +1 -0
  9. package/dist/core/select-boolean.test.d.ts +1 -0
  10. package/dist/core/select-pool.test.d.ts +1 -0
  11. package/dist/core/select.d.ts +278 -86
  12. package/dist/core/types.d.ts +233 -1
  13. package/dist/core/withAbort.d.ts +95 -0
  14. package/dist/core/withReady.d.ts +3 -3
  15. package/dist/devtools/constants.d.ts +41 -0
  16. package/dist/devtools/index.cjs +1 -0
  17. package/dist/devtools/index.d.ts +29 -0
  18. package/dist/devtools/index.js +429 -0
  19. package/dist/devtools/registry.d.ts +98 -0
  20. package/dist/devtools/registry.test.d.ts +1 -0
  21. package/dist/devtools/setup.d.ts +61 -0
  22. package/dist/devtools/types.d.ts +311 -0
  23. package/dist/index-BZEnfIcB.cjs +1 -0
  24. package/dist/index-BbPZhsDl.js +1653 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.ts +4 -3
  27. package/dist/index.js +18 -14
  28. package/dist/onDispatchHook-C8yLzr-o.cjs +1 -0
  29. package/dist/onDispatchHook-SKbiIUaJ.js +5 -0
  30. package/dist/onErrorHook-BGGy3tqK.js +38 -0
  31. package/dist/onErrorHook-DHBASmYw.cjs +1 -0
  32. package/dist/react/index.cjs +1 -1
  33. package/dist/react/index.js +191 -151
  34. package/dist/react/onDispatchHook.d.ts +106 -0
  35. package/dist/react/useAction.d.ts +4 -1
  36. package/dist/react-devtools/DevToolsPanel.d.ts +93 -0
  37. package/dist/react-devtools/EntityDetails.d.ts +10 -0
  38. package/dist/react-devtools/EntityList.d.ts +15 -0
  39. package/dist/react-devtools/LogList.d.ts +12 -0
  40. package/dist/react-devtools/hooks.d.ts +50 -0
  41. package/dist/react-devtools/index.cjs +1 -0
  42. package/dist/react-devtools/index.d.ts +31 -0
  43. package/dist/react-devtools/index.js +1589 -0
  44. package/dist/react-devtools/styles.d.ts +148 -0
  45. package/package.json +26 -2
  46. package/skills/atomirx/SKILL.md +456 -0
  47. package/skills/atomirx/references/async-patterns.md +188 -0
  48. package/skills/atomirx/references/atom-patterns.md +238 -0
  49. package/skills/atomirx/references/deferred-loading.md +191 -0
  50. package/skills/atomirx/references/derived-patterns.md +428 -0
  51. package/skills/atomirx/references/effect-patterns.md +426 -0
  52. package/skills/atomirx/references/error-handling.md +140 -0
  53. package/skills/atomirx/references/hooks.md +322 -0
  54. package/skills/atomirx/references/pool-patterns.md +229 -0
  55. package/skills/atomirx/references/react-integration.md +411 -0
  56. package/skills/atomirx/references/rules.md +407 -0
  57. package/skills/atomirx/references/select-context.md +309 -0
  58. package/skills/atomirx/references/service-template.md +172 -0
  59. package/skills/atomirx/references/store-template.md +205 -0
  60. package/skills/atomirx/references/testing-patterns.md +431 -0
  61. package/coverage/base.css +0 -224
  62. package/coverage/block-navigation.js +0 -87
  63. package/coverage/clover.xml +0 -1440
  64. package/coverage/coverage-final.json +0 -14
  65. package/coverage/favicon.png +0 -0
  66. package/coverage/index.html +0 -131
  67. package/coverage/prettify.css +0 -1
  68. package/coverage/prettify.js +0 -2
  69. package/coverage/sort-arrow-sprite.png +0 -0
  70. package/coverage/sorter.js +0 -210
  71. package/coverage/src/core/atom.ts.html +0 -889
  72. package/coverage/src/core/batch.ts.html +0 -223
  73. package/coverage/src/core/define.ts.html +0 -805
  74. package/coverage/src/core/emitter.ts.html +0 -919
  75. package/coverage/src/core/equality.ts.html +0 -631
  76. package/coverage/src/core/hook.ts.html +0 -460
  77. package/coverage/src/core/index.html +0 -281
  78. package/coverage/src/core/isAtom.ts.html +0 -100
  79. package/coverage/src/core/isPromiseLike.ts.html +0 -133
  80. package/coverage/src/core/onCreateHook.ts.html +0 -138
  81. package/coverage/src/core/scheduleNotifyHook.ts.html +0 -94
  82. package/coverage/src/core/types.ts.html +0 -523
  83. package/coverage/src/core/withUse.ts.html +0 -253
  84. package/coverage/src/index.html +0 -116
  85. package/coverage/src/index.ts.html +0 -106
  86. package/dist/index-CBVj1kSj.js +0 -1350
  87. package/dist/index-Cxk9v0um.cjs +0 -1
  88. package/scripts/publish.js +0 -198
  89. package/src/core/atom.test.ts +0 -633
  90. package/src/core/atom.ts +0 -311
  91. package/src/core/atomState.test.ts +0 -342
  92. package/src/core/atomState.ts +0 -256
  93. package/src/core/batch.test.ts +0 -257
  94. package/src/core/batch.ts +0 -172
  95. package/src/core/define.test.ts +0 -343
  96. package/src/core/define.ts +0 -243
  97. package/src/core/derived.test.ts +0 -1215
  98. package/src/core/derived.ts +0 -450
  99. package/src/core/effect.test.ts +0 -802
  100. package/src/core/effect.ts +0 -188
  101. package/src/core/emitter.test.ts +0 -364
  102. package/src/core/emitter.ts +0 -392
  103. package/src/core/equality.test.ts +0 -392
  104. package/src/core/equality.ts +0 -182
  105. package/src/core/getAtomState.ts +0 -69
  106. package/src/core/hook.test.ts +0 -227
  107. package/src/core/hook.ts +0 -177
  108. package/src/core/isAtom.ts +0 -27
  109. package/src/core/isPromiseLike.test.ts +0 -72
  110. package/src/core/isPromiseLike.ts +0 -16
  111. package/src/core/onCreateHook.ts +0 -107
  112. package/src/core/onErrorHook.test.ts +0 -350
  113. package/src/core/onErrorHook.ts +0 -52
  114. package/src/core/promiseCache.test.ts +0 -241
  115. package/src/core/promiseCache.ts +0 -284
  116. package/src/core/scheduleNotifyHook.ts +0 -53
  117. package/src/core/select.ts +0 -729
  118. package/src/core/selector.test.ts +0 -799
  119. package/src/core/types.ts +0 -389
  120. package/src/core/withReady.test.ts +0 -534
  121. package/src/core/withReady.ts +0 -191
  122. package/src/core/withUse.test.ts +0 -249
  123. package/src/core/withUse.ts +0 -56
  124. package/src/index.test.ts +0 -80
  125. package/src/index.ts +0 -65
  126. package/src/react/index.ts +0 -21
  127. package/src/react/rx.test.tsx +0 -571
  128. package/src/react/rx.tsx +0 -531
  129. package/src/react/strictModeTest.tsx +0 -71
  130. package/src/react/useAction.test.ts +0 -987
  131. package/src/react/useAction.ts +0 -607
  132. package/src/react/useSelector.test.ts +0 -182
  133. package/src/react/useSelector.ts +0 -292
  134. package/src/react/useStable.test.ts +0 -553
  135. package/src/react/useStable.ts +0 -288
  136. package/tsconfig.json +0 -9
  137. package/v2.md +0 -725
  138. package/vite.config.ts +0 -42
@@ -1,288 +0,0 @@
1
- import { useRef } from "react";
2
- import { resolveEquality, tryStabilize, StableFn } from "../core/equality";
3
- import type { AnyFunc, Equality } from "../core/types";
4
-
5
- /**
6
- * Extracts non-function keys from an object type.
7
- */
8
- type NonFunctionKeys<T> = {
9
- [K in keyof T]: T[K] extends AnyFunc ? never : K;
10
- }[keyof T];
11
-
12
- /**
13
- * Equals options for useStable - only non-function properties can have custom equality.
14
- */
15
- export type UseStableEquals<T> = {
16
- [K in NonFunctionKeys<T>]?: Equality<T[K]>;
17
- };
18
-
19
- /**
20
- * Result type for useStable - functions are wrapped in StableFn.
21
- */
22
- export type UseStableResult<T> = {
23
- [K in keyof T]: T[K] extends (...args: infer A) => infer R
24
- ? StableFn<A, R>
25
- : T[K];
26
- };
27
-
28
- /**
29
- * Storage for each property's previous value.
30
- */
31
- type PropertyStorage<T> = {
32
- [K in keyof T]?: { value: T[K] };
33
- };
34
-
35
- /**
36
- * Determines the default equality strategy based on value type.
37
- *
38
- * - Array → 'shallow' (compare items by reference)
39
- * - Date → handled specially in tryStabilize (timestamp comparison)
40
- * - Object → 'shallow' (compare keys by reference)
41
- * - Primitives → 'strict' (reference equality)
42
- */
43
- function getDefaultEquality<T>(value: T): Equality<T> {
44
- if (value === null || value === undefined) {
45
- return "strict";
46
- }
47
-
48
- if (Array.isArray(value)) {
49
- return "shallow";
50
- }
51
-
52
- if (value instanceof Date) {
53
- // Date is handled specially in tryStabilize, but we return deep
54
- // to ensure proper comparison if tryStabilize doesn't catch it
55
- return "deep";
56
- }
57
-
58
- if (typeof value === "object") {
59
- return "shallow";
60
- }
61
-
62
- return "strict";
63
- }
64
-
65
- /**
66
- * React hook that provides stable references for objects, arrays, and callbacks.
67
- *
68
- * `useStable` solves the common React problem of unstable references causing
69
- * unnecessary re-renders, useEffect re-runs, and useCallback/useMemo invalidations.
70
- *
71
- * ## Why Use `useStable`?
72
- *
73
- * In React, inline objects, arrays, and callbacks create new references on every render:
74
- *
75
- * ```tsx
76
- * // ❌ Problem: new reference every render
77
- * function Parent() {
78
- * const config = { theme: 'dark' }; // New object every render!
79
- * const onClick = () => doSomething(); // New function every render!
80
- * return <Child config={config} onClick={onClick} />;
81
- * }
82
- *
83
- * // ✅ Solution: stable references
84
- * function Parent() {
85
- * const stable = useStable({
86
- * config: { theme: 'dark' },
87
- * onClick: () => doSomething(),
88
- * });
89
- * return <Child config={stable.config} onClick={stable.onClick} />;
90
- * }
91
- * ```
92
- *
93
- * ## How It Works
94
- *
95
- * Each property is independently stabilized based on its type:
96
- *
97
- * | Type | Default Equality | Behavior |
98
- * |------|------------------|----------|
99
- * | **Functions** | N/A (always wrapped) | Reference never changes, calls latest implementation |
100
- * | **Arrays** | shallow | Stable if items are reference-equal |
101
- * | **Dates** | timestamp | Stable if same time value |
102
- * | **Objects** | shallow | Stable if keys have reference-equal values |
103
- * | **Primitives** | strict | Stable if same value |
104
- *
105
- * ## Key Benefits
106
- *
107
- * 1. **Stable callbacks**: Functions maintain reference identity while always calling latest implementation
108
- * 2. **Stable objects/arrays**: Prevent unnecessary child re-renders
109
- * 3. **Safe for deps arrays**: Use in useEffect, useMemo, useCallback deps
110
- * 4. **Per-property equality**: Customize comparison strategy for each property
111
- * 5. **No wrapper overhead**: Returns the same result object reference
112
- *
113
- * @template T - The type of the input object
114
- * @param input - Object with properties to stabilize
115
- * @param equals - Optional custom equality strategies per property (except functions)
116
- * @returns Stable object with same properties (functions wrapped in StableFn)
117
- *
118
- * @example Basic usage - stable callbacks and objects
119
- * ```tsx
120
- * function MyComponent({ userId }) {
121
- * const stable = useStable({
122
- * // Object - stable if shallow equal
123
- * config: { theme: 'dark', userId },
124
- * // Array - stable if items are reference-equal
125
- * items: [1, 2, 3],
126
- * // Function - reference never changes
127
- * onClick: () => console.log('clicked', userId),
128
- * });
129
- *
130
- * // Safe to use in deps - won't cause infinite loops
131
- * useEffect(() => {
132
- * console.log(stable.config);
133
- * }, [stable.config]);
134
- *
135
- * // stable.onClick is always the same reference
136
- * return <button onClick={stable.onClick}>Click</button>;
137
- * }
138
- * ```
139
- *
140
- * @example Preventing child re-renders
141
- * ```tsx
142
- * function Parent() {
143
- * const [count, setCount] = useState(0);
144
- *
145
- * const stable = useStable({
146
- * // These won't cause Child to re-render when count changes
147
- * user: { id: 1, name: 'John' },
148
- * onSave: () => saveUser(),
149
- * });
150
- *
151
- * return (
152
- * <div>
153
- * <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
154
- * <MemoizedChild user={stable.user} onSave={stable.onSave} />
155
- * </div>
156
- * );
157
- * }
158
- * ```
159
- *
160
- * @example Custom equality per property
161
- * ```tsx
162
- * const stable = useStable(
163
- * {
164
- * user: { id: 1, profile: { name: "John", avatar: "..." } },
165
- * tags: ["react", "typescript"],
166
- * settings: { theme: "dark" },
167
- * },
168
- * {
169
- * user: "deep", // Deep compare nested objects
170
- * tags: "strict", // Override default shallow for arrays
171
- * settings: "shallow", // Explicit shallow (same as default)
172
- * }
173
- * );
174
- * ```
175
- *
176
- * @example Custom equality function
177
- * ```tsx
178
- * const stable = useStable(
179
- * { user: { id: 1, name: "John", updatedAt: new Date() } },
180
- * {
181
- * // Only compare by id - ignore name and updatedAt changes
182
- * user: (a, b) => a?.id === b?.id
183
- * }
184
- * );
185
- * // stable.user reference only changes when id changes
186
- * ```
187
- *
188
- * @example With useEffect deps
189
- * ```tsx
190
- * function DataFetcher({ filters }) {
191
- * const stable = useStable({
192
- * filters: { ...filters, timestamp: Date.now() },
193
- * onSuccess: (data) => processData(data),
194
- * });
195
- *
196
- * useEffect(() => {
197
- * // Only re-runs when filters actually change (shallow comparison)
198
- * fetchData(stable.filters).then(stable.onSuccess);
199
- * }, [stable.filters, stable.onSuccess]);
200
- * }
201
- * ```
202
- *
203
- * @example Stable event handlers for lists
204
- * ```tsx
205
- * function TodoList({ todos }) {
206
- * const stable = useStable({
207
- * onDelete: (id) => deleteTodo(id),
208
- * onToggle: (id) => toggleTodo(id),
209
- * });
210
- *
211
- * return (
212
- * <ul>
213
- * {todos.map(todo => (
214
- * <TodoItem
215
- * key={todo.id}
216
- * todo={todo}
217
- * onDelete={stable.onDelete} // Same reference for all items
218
- * onToggle={stable.onToggle} // Prevents unnecessary re-renders
219
- * />
220
- * ))}
221
- * </ul>
222
- * );
223
- * }
224
- * ```
225
- */
226
- export function useStable<T extends Record<string, unknown>>(
227
- input: T,
228
- equals?: UseStableEquals<T>
229
- ): UseStableResult<T> {
230
- // Store previous values for each property
231
- const storageRef = useRef<PropertyStorage<T>>({});
232
-
233
- // Store the stable result object (reference never changes)
234
- const resultRef = useRef<UseStableResult<T> | null>(null);
235
-
236
- // Initialize result object on first render
237
- if (resultRef.current === null) {
238
- resultRef.current = {} as UseStableResult<T>;
239
- }
240
-
241
- const storage = storageRef.current;
242
- const result = resultRef.current;
243
-
244
- // Process each property
245
- for (const key of Object.keys(input) as (keyof T)[]) {
246
- const nextValue = input[key];
247
- const prevStorage = storage[key];
248
-
249
- // Functions are always stabilized, ignore equality option
250
- if (typeof nextValue === "function") {
251
- const [stabilized] = tryStabilize(
252
- prevStorage as { value: AnyFunc } | undefined,
253
- nextValue as AnyFunc,
254
- () => false // Equality doesn't matter for functions
255
- );
256
-
257
- storage[key] = { value: stabilized as T[typeof key] };
258
- (result as Record<keyof T, unknown>)[key] = stabilized;
259
- continue;
260
- }
261
-
262
- // Get equality function for this property
263
- const customEquals = equals?.[key as NonFunctionKeys<T>];
264
- const equalityFn = customEquals
265
- ? resolveEquality(customEquals as Equality<T[typeof key]>)
266
- : resolveEquality(getDefaultEquality(nextValue));
267
-
268
- // Stabilize the value
269
- const [stabilized] = tryStabilize(
270
- prevStorage,
271
- nextValue,
272
- equalityFn as (a: T[typeof key], b: T[typeof key]) => boolean
273
- );
274
-
275
- storage[key] = { value: stabilized };
276
- (result as Record<keyof T, unknown>)[key] = stabilized;
277
- }
278
-
279
- // Handle removed properties (set to undefined)
280
- for (const key of Object.keys(storage) as (keyof T)[]) {
281
- if (!(key in input)) {
282
- delete storage[key];
283
- delete (result as Record<keyof T, unknown>)[key];
284
- }
285
- }
286
-
287
- return result;
288
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "outDir": "dist",
6
- "declaration": true
7
- },
8
- "include": ["src"]
9
- }