floppy-disk 1.4.0 → 1.4.1-beta.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.
- package/README.md +20 -26
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@ This library was highly-inspired by [Zustand](https://www.npmjs.com/package/zust
|
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
10
|
import { create } from 'zustand'; // 3.3 kB (gzipped: 1.5 kB)
|
|
11
|
-
|
|
12
11
|
import { createStore } from 'floppy-disk'; // 1.3 kB (gzipped: 702 B) 🎉
|
|
13
12
|
|
|
14
13
|
import {
|
|
@@ -18,14 +17,13 @@ import {
|
|
|
18
17
|
useInfiniteQuery,
|
|
19
18
|
useMutation,
|
|
20
19
|
} from '@tanstack/react-query'; // 41 kB (gzipped: 11 kB)
|
|
21
|
-
|
|
22
20
|
import { createQuery, createMutation } from 'floppy-disk'; // 7.5 kB (gzipped: 2.6 kB) 🎉
|
|
23
21
|
```
|
|
24
22
|
|
|
25
23
|
- Using Zustand & React-Query: https://demo-zustand-react-query.vercel.app/
|
|
26
|
-
👉 Total: **309.22 kB**
|
|
24
|
+
👉 Total: **309.22 kB**
|
|
27
25
|
- Using Floppy Disk: https://demo-floppy-disk.vercel.app/
|
|
28
|
-
👉 Total: **282.86 kB**
|
|
26
|
+
👉 Total: **282.86 kB** 🎉
|
|
29
27
|
|
|
30
28
|
## Table of Contents
|
|
31
29
|
|
|
@@ -71,6 +69,8 @@ function Control() {
|
|
|
71
69
|
}
|
|
72
70
|
```
|
|
73
71
|
|
|
72
|
+
> Example: [https://codesandbox.io/.../examples/react/basic](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/basic)
|
|
73
|
+
|
|
74
74
|
Control the reactivity. The concept is same as useEffect dependency array.
|
|
75
75
|
|
|
76
76
|
```jsx
|
|
@@ -100,6 +100,8 @@ function Cat() {
|
|
|
100
100
|
}
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
> Example: [https://codesandbox.io/.../examples/react/custom-reactivity](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/custom-reactivity)
|
|
104
|
+
|
|
103
105
|
Reading/writing state and reacting to changes outside of components.
|
|
104
106
|
|
|
105
107
|
```js
|
|
@@ -122,11 +124,6 @@ const unsub = useCatStore.subscribe(
|
|
|
122
124
|
);
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
> **Examples:**
|
|
126
|
-
>
|
|
127
|
-
> - [https://codesandbox.io/.../examples/react/basic](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/basic)
|
|
128
|
-
> - [https://codesandbox.io/.../examples/react/custom-reactivity](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/custom-reactivity)
|
|
129
|
-
|
|
130
127
|
### Advanced Concept
|
|
131
128
|
|
|
132
129
|
Set the state **silently** (without broadcast the state change to **any subscribers**).
|
|
@@ -176,10 +173,9 @@ const useCatStore = createStore(
|
|
|
176
173
|
);
|
|
177
174
|
```
|
|
178
175
|
|
|
179
|
-
>
|
|
180
|
-
>
|
|
181
|
-
>
|
|
182
|
-
> - [https://codesandbox.io/.../examples/react/intercept](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/intercept)
|
|
176
|
+
> Example:
|
|
177
|
+
> [https://codesandbox.io/.../examples/react/store-event](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/store-event)
|
|
178
|
+
> [https://codesandbox.io/.../examples/react/intercept](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/intercept)
|
|
183
179
|
|
|
184
180
|
Let's go wild using IIFE.
|
|
185
181
|
|
|
@@ -238,9 +234,7 @@ function CatPageOptimized() {
|
|
|
238
234
|
}
|
|
239
235
|
```
|
|
240
236
|
|
|
241
|
-
>
|
|
242
|
-
>
|
|
243
|
-
> - [https://codesandbox.io/.../examples/react/watch-component](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/watch-component)
|
|
237
|
+
> Example: [https://codesandbox.io/.../examples/react/watch-component](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/watch-component)
|
|
244
238
|
|
|
245
239
|
Want a local state instead of global state?
|
|
246
240
|
Or, want to set the initial state inside component?
|
|
@@ -289,12 +283,14 @@ function CatIsSleeping() {
|
|
|
289
283
|
return (
|
|
290
284
|
<>
|
|
291
285
|
<div>Is Sleeping: {String(isSleeping)}</div>
|
|
292
|
-
<button onClick={useCatStore.get().
|
|
286
|
+
<button onClick={useCatStore.get().increaseAge}>Increase cat age</button>
|
|
293
287
|
</>
|
|
294
288
|
);
|
|
295
289
|
}
|
|
296
290
|
```
|
|
297
291
|
|
|
292
|
+
> Example: [https://codesandbox.io/.../examples/react/local-state](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/local-state)
|
|
293
|
+
|
|
298
294
|
Set default reactivity.
|
|
299
295
|
|
|
300
296
|
```jsx
|
|
@@ -368,9 +364,7 @@ function Control({ catId }) {
|
|
|
368
364
|
}
|
|
369
365
|
```
|
|
370
366
|
|
|
371
|
-
>
|
|
372
|
-
>
|
|
373
|
-
> - [https://codesandbox.io/.../examples/react/stores](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/stores)
|
|
367
|
+
> Example: [https://codesandbox.io/.../examples/react/stores](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/stores)
|
|
374
368
|
|
|
375
369
|
## Query & Mutation
|
|
376
370
|
|
|
@@ -403,9 +397,7 @@ function SingleQuery() {
|
|
|
403
397
|
}
|
|
404
398
|
```
|
|
405
399
|
|
|
406
|
-
>
|
|
407
|
-
>
|
|
408
|
-
> - [https://codesandbox.io/.../examples/react/query](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/query)
|
|
400
|
+
> Example: [https://codesandbox.io/.../examples/react/query](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/query)
|
|
409
401
|
|
|
410
402
|
Custom reactivity:
|
|
411
403
|
|
|
@@ -501,6 +493,8 @@ function PokemonPage() {
|
|
|
501
493
|
}
|
|
502
494
|
```
|
|
503
495
|
|
|
496
|
+
> Example: [https://codesandbox.io/.../examples/react/query-with-param](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/query-with-param)
|
|
497
|
+
|
|
504
498
|
Get data or do something outside component:
|
|
505
499
|
|
|
506
500
|
```jsx
|
|
@@ -558,6 +552,8 @@ function PokemonListPage() {
|
|
|
558
552
|
}
|
|
559
553
|
```
|
|
560
554
|
|
|
555
|
+
> Example: [https://codesandbox.io/.../examples/react/infinite-query](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/infinite-query)
|
|
556
|
+
|
|
561
557
|
**Note:**
|
|
562
558
|
|
|
563
559
|
- The default stale time is 3 seconds.
|
|
@@ -609,9 +605,7 @@ function Login() {
|
|
|
609
605
|
}
|
|
610
606
|
```
|
|
611
607
|
|
|
612
|
-
>
|
|
613
|
-
>
|
|
614
|
-
> - [https://codesandbox.io/.../examples/react/mutation](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/mutation)
|
|
608
|
+
> Example: [https://codesandbox.io/.../examples/react/mutation](https://codesandbox.io/p/sandbox/github/afiiif/floppy-disk/tree/main/examples/react/mutation)
|
|
615
609
|
|
|
616
610
|
<br><br>
|
|
617
611
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "floppy-disk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1-beta.1",
|
|
4
4
|
"description": "FloppyDisk - lightweight, simple, and powerful state management library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -30,9 +30,6 @@
|
|
|
30
30
|
],
|
|
31
31
|
"types": "lib/index.d.ts",
|
|
32
32
|
"typings": "lib/index.d.ts",
|
|
33
|
-
"engines": {
|
|
34
|
-
"node": ">=14"
|
|
35
|
-
},
|
|
36
33
|
"scripts": {
|
|
37
34
|
"prepare": "husky install",
|
|
38
35
|
"build:cjs": "tsc -p tsconfig.prod.json",
|