@but212/atom-effect 0.2.1 → 0.2.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/README.md +1 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,43 +162,6 @@ effect(() => {
|
|
|
162
162
|
});
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
### API Integration
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
const userId = atom(1);
|
|
169
|
-
const userData = computed(async () => {
|
|
170
|
-
const res = await fetch(`/api/users/${userId.value}`);
|
|
171
|
-
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
|
|
172
|
-
return res.json();
|
|
173
|
-
}, {
|
|
174
|
-
defaultValue: null,
|
|
175
|
-
onError: (e) => console.error('Failed to fetch user data:', e)
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
effect(() => {
|
|
179
|
-
if (userData.value) {
|
|
180
|
-
console.log('User loaded:', userData.value.name);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Persistent State
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
function persistentAtom<T>(key: string, initialValue: T) {
|
|
189
|
-
const stored = localStorage.getItem(key);
|
|
190
|
-
const a = atom<T>(stored ? JSON.parse(stored) : initialValue);
|
|
191
|
-
|
|
192
|
-
effect(() => {
|
|
193
|
-
localStorage.setItem(key, JSON.stringify(a.value));
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
return a;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const theme = persistentAtom('theme', 'light');
|
|
200
|
-
```
|
|
201
|
-
|
|
202
165
|
## Utilities
|
|
203
166
|
|
|
204
167
|
### Type Guards
|
|
@@ -256,7 +219,7 @@ See [docs/BENCHMARKS.md](./docs/BENCHMARKS.md) for details.
|
|
|
256
219
|
## Testing
|
|
257
220
|
|
|
258
221
|
```bash
|
|
259
|
-
pnpm test # Run all tests (
|
|
222
|
+
pnpm test # Run all tests (296 test cases)
|
|
260
223
|
pnpm test:coverage # With coverage
|
|
261
224
|
pnpm bench # Run benchmarks
|
|
262
225
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@but212/atom-effect",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A reactive state management library that combines the power of `atom`, `computed`, and `effect` for seamless management of reactive state.",
|
|
6
6
|
"main": "./dist/index.cjs",
|