floppy-disk 3.1.0 → 3.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.
- package/README.md +20 -17
- package/esm/index.d.mts +1 -1
- package/esm/react/create-mutation.d.mts +4 -4
- package/esm/react/create-query.d.mts +5 -5
- package/esm/react/create-store.d.mts +1 -1
- package/esm/react/create-stores.d.mts +1 -1
- package/esm/react/use-isomorphic-layout-effect.d.mts +1 -1
- package/esm/react/use-mutation.d.mts +1 -1
- package/esm/react/use-store.d.mts +1 -1
- package/esm/react.d.mts +7 -7
- package/esm/vanilla.d.mts +3 -3
- package/index.d.ts +1 -1
- package/package.json +2 -2
- package/react/create-mutation.d.ts +4 -4
- package/react/create-query.d.ts +5 -5
- package/react/create-store.d.ts +1 -1
- package/react/create-stores.d.ts +1 -1
- package/react/use-isomorphic-layout-effect.d.ts +1 -1
- package/react/use-mutation.d.ts +1 -1
- package/react/use-store.d.ts +1 -1
- package/react.d.ts +7 -7
- package/vanilla.d.ts +3 -3
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# FloppyDisk.ts 💾
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A unified state model for **sync & async** data.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
If you know [Zustand](https://zustand.docs.pmnd.rs) & [TanStack-Query](https://tanstack.com/query), you already know FloppyDisk.\
|
|
6
|
+
It keeps what works, removes unnecessary complexity, and unifies everything into a simpler API.\
|
|
7
|
+
No relearning—just a better experience.
|
|
8
|
+
|
|
9
|
+
_Smaller bundle. Zero dependencies._
|
|
7
10
|
|
|
8
11
|
Demo: https://afiiif.github.io/floppy-disk/
|
|
9
12
|
|
|
@@ -18,11 +21,11 @@ npm install floppy-disk
|
|
|
18
21
|
Here's how to create and use a store:
|
|
19
22
|
|
|
20
23
|
```tsx
|
|
21
|
-
import { createStore } from
|
|
24
|
+
import { createStore } from "floppy-disk/react";
|
|
22
25
|
|
|
23
26
|
const useDigimon = createStore({
|
|
24
27
|
age: 7,
|
|
25
|
-
level:
|
|
28
|
+
level: "Rookie",
|
|
26
29
|
});
|
|
27
30
|
```
|
|
28
31
|
|
|
@@ -57,10 +60,10 @@ function Control() {
|
|
|
57
60
|
const evolve = () => {
|
|
58
61
|
const { level } = useDigimon.getState();
|
|
59
62
|
|
|
60
|
-
const order = [
|
|
63
|
+
const order = ["In-Training", "Rookie", "Champion", "Ultimate"];
|
|
61
64
|
const nextLevel = order[order.indexOf(level) + 1];
|
|
62
65
|
|
|
63
|
-
if (!nextLevel) return console.warn(
|
|
66
|
+
if (!nextLevel) return console.warn("Already at ultimate level");
|
|
64
67
|
|
|
65
68
|
useDigimon.setState({ level: nextLevel });
|
|
66
69
|
};
|
|
@@ -74,7 +77,7 @@ You can subscribe manually:
|
|
|
74
77
|
|
|
75
78
|
```tsx
|
|
76
79
|
const unsubscribe = useMyStore.subscribe((state, prev) => {
|
|
77
|
-
console.log(
|
|
80
|
+
console.log("New state:", state);
|
|
78
81
|
});
|
|
79
82
|
|
|
80
83
|
// Later
|
|
@@ -88,16 +91,16 @@ const useTowerDefense = createStore(
|
|
|
88
91
|
{ archers: 3, mages: 1, barracks: 2, artillery: 1 },
|
|
89
92
|
{
|
|
90
93
|
onFirstSubscribe: () => {
|
|
91
|
-
console.log(
|
|
94
|
+
console.log("First subscriber! We’re officially popular 🎉");
|
|
92
95
|
},
|
|
93
96
|
onSubscribe: () => {
|
|
94
|
-
console.log(
|
|
97
|
+
console.log("New subscriber joined. Welcome aboard 🫡");
|
|
95
98
|
},
|
|
96
99
|
onUnsubscribe: () => {
|
|
97
|
-
console.log(
|
|
100
|
+
console.log("Subscriber left... was it something I said? 😭");
|
|
98
101
|
},
|
|
99
102
|
onLastUnsubscribe: () => {
|
|
100
|
-
console.log(
|
|
103
|
+
console.log("Everyone left. Guess I’ll just exist quietly now...");
|
|
101
104
|
},
|
|
102
105
|
},
|
|
103
106
|
);
|
|
@@ -212,7 +215,7 @@ If you need retry mechanism, then you can always add it manually.
|
|
|
212
215
|
Create a query using `createQuery`:
|
|
213
216
|
|
|
214
217
|
```tsx
|
|
215
|
-
import { createQuery } from
|
|
218
|
+
import { createQuery } from "floppy-disk/react";
|
|
216
219
|
|
|
217
220
|
const myCoolQuery = createQuery(
|
|
218
221
|
myAsyncFn,
|
|
@@ -225,7 +228,7 @@ const useMyCoolQuery = myCoolQuery();
|
|
|
225
228
|
|
|
226
229
|
function MyComponent() {
|
|
227
230
|
const query = useMyCoolQuery();
|
|
228
|
-
if (query.state ===
|
|
231
|
+
if (query.state === "INITIAL") return <div>Loading...</div>;
|
|
229
232
|
if (query.error) return <div>Error: {query.error.message}</div>;
|
|
230
233
|
return <div>{JSON.stringify(query.data)}</div>;
|
|
231
234
|
}
|
|
@@ -259,7 +262,7 @@ const value = useMyQuery().data?.foo.bar.baz;
|
|
|
259
262
|
You can create parameterized queries:
|
|
260
263
|
|
|
261
264
|
```tsx
|
|
262
|
-
import { getUserById, type GetUserByIdResponse } from
|
|
265
|
+
import { getUserById, type GetUserByIdResponse } from "../utils";
|
|
263
266
|
|
|
264
267
|
type MyQueryParam = { id: string };
|
|
265
268
|
|
|
@@ -275,7 +278,7 @@ Use it with parameters:
|
|
|
275
278
|
function UserDetail({ id }) {
|
|
276
279
|
const useUserQuery = userQuery({ id: 1 });
|
|
277
280
|
const query = useUserQuery();
|
|
278
|
-
if (query.state ===
|
|
281
|
+
if (query.state === "INITIAL") return <div>Loading...</div>;
|
|
279
282
|
if (query.error) return <div>Error: {query.error.message}</div>;
|
|
280
283
|
return <div>{JSON.stringify(query.data)}</div>;
|
|
281
284
|
}
|
|
@@ -323,7 +326,7 @@ function Page({ cursor }: { cursor?: string }) {
|
|
|
323
326
|
const usePostsQuery = postsQuery({ cursor });
|
|
324
327
|
const { state, data, error } = usePostsQuery();
|
|
325
328
|
|
|
326
|
-
if (state ===
|
|
329
|
+
if (state === "INITIAL") return <div>Loading...</div>;
|
|
327
330
|
if (error) return <div>Error</div>;
|
|
328
331
|
|
|
329
332
|
return (
|
package/esm/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./vanilla.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InitStoreOptions, type SetState } from
|
|
1
|
+
import { type InitStoreOptions, type SetState } from "../vanilla.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Represents the state of a mutation.
|
|
4
4
|
*
|
|
@@ -17,7 +17,7 @@ import { type InitStoreOptions, type SetState } from 'floppy-disk/vanilla';
|
|
|
17
17
|
export type MutationState<TData, TVariable, TError> = {
|
|
18
18
|
isPending: boolean;
|
|
19
19
|
} & ({
|
|
20
|
-
state:
|
|
20
|
+
state: "INITIAL";
|
|
21
21
|
isSuccess: false;
|
|
22
22
|
isError: false;
|
|
23
23
|
variable: undefined;
|
|
@@ -26,7 +26,7 @@ export type MutationState<TData, TVariable, TError> = {
|
|
|
26
26
|
error: undefined;
|
|
27
27
|
errorUpdatedAt: undefined;
|
|
28
28
|
} | {
|
|
29
|
-
state:
|
|
29
|
+
state: "SUCCESS";
|
|
30
30
|
isSuccess: true;
|
|
31
31
|
isError: false;
|
|
32
32
|
variable: TVariable;
|
|
@@ -35,7 +35,7 @@ export type MutationState<TData, TVariable, TError> = {
|
|
|
35
35
|
error: undefined;
|
|
36
36
|
errorUpdatedAt: undefined;
|
|
37
37
|
} | {
|
|
38
|
-
state:
|
|
38
|
+
state: "ERROR";
|
|
39
39
|
isSuccess: false;
|
|
40
40
|
isError: true;
|
|
41
41
|
variable: TVariable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InitStoreOptions, type SetState } from
|
|
1
|
+
import { type InitStoreOptions, type SetState } from "../vanilla.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Represents the state of a query.
|
|
4
4
|
*
|
|
@@ -25,7 +25,7 @@ export type QueryState<TData, TError> = {
|
|
|
25
25
|
isRetrying: boolean;
|
|
26
26
|
retryCount: number;
|
|
27
27
|
} & ({
|
|
28
|
-
state:
|
|
28
|
+
state: "INITIAL";
|
|
29
29
|
isSuccess: false;
|
|
30
30
|
isError: false;
|
|
31
31
|
data: undefined;
|
|
@@ -33,7 +33,7 @@ export type QueryState<TData, TError> = {
|
|
|
33
33
|
error: undefined;
|
|
34
34
|
errorUpdatedAt: undefined;
|
|
35
35
|
} | {
|
|
36
|
-
state:
|
|
36
|
+
state: "SUCCESS";
|
|
37
37
|
isSuccess: true;
|
|
38
38
|
isError: false;
|
|
39
39
|
data: TData;
|
|
@@ -41,7 +41,7 @@ export type QueryState<TData, TError> = {
|
|
|
41
41
|
error: undefined;
|
|
42
42
|
errorUpdatedAt: undefined;
|
|
43
43
|
} | {
|
|
44
|
-
state:
|
|
44
|
+
state: "ERROR";
|
|
45
45
|
isSuccess: false;
|
|
46
46
|
isError: true;
|
|
47
47
|
data: undefined;
|
|
@@ -49,7 +49,7 @@ export type QueryState<TData, TError> = {
|
|
|
49
49
|
error: TError;
|
|
50
50
|
errorUpdatedAt: number;
|
|
51
51
|
} | {
|
|
52
|
-
state:
|
|
52
|
+
state: "SUCCESS_BUT_REVALIDATION_ERROR";
|
|
53
53
|
isSuccess: true;
|
|
54
54
|
isError: false;
|
|
55
55
|
data: TData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StoreApi } from
|
|
1
|
+
import { type StoreApi } from "../vanilla.ts";
|
|
2
2
|
type Path = Array<string | number | symbol>;
|
|
3
3
|
export declare const getValueByPath: (obj: any, path: Path) => any;
|
|
4
4
|
export declare const isPrefixPath: (candidatePrefix: Path, targetPath: Path) => boolean;
|
package/esm/react.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export { useStoreState } from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export { createMutation, type MutationOptions, type MutationState, } from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./react/use-isomorphic-layout-effect.ts";
|
|
2
|
+
export { useStoreState } from "./react/use-store.ts";
|
|
3
|
+
export * from "./react/create-store.ts";
|
|
4
|
+
export * from "./react/create-stores.ts";
|
|
5
|
+
export * from "./react/create-query.ts";
|
|
6
|
+
export { createMutation, type MutationOptions, type MutationState, } from "./react/create-mutation.ts";
|
|
7
|
+
export * from "./react/use-mutation.ts";
|
package/esm/vanilla.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./vanilla/basic.ts";
|
|
2
|
+
export * from "./vanilla/hash.ts";
|
|
3
|
+
export * from "./vanilla/store.ts";
|
package/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./vanilla.ts";
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "floppy-disk",
|
|
3
|
-
"description": "Lightweight
|
|
3
|
+
"description": "Lightweight unified state management for sync and async data.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.1.
|
|
5
|
+
"version": "3.1.1",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utilities",
|
|
8
8
|
"store",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InitStoreOptions, type SetState } from
|
|
1
|
+
import { type InitStoreOptions, type SetState } from "../vanilla.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Represents the state of a mutation.
|
|
4
4
|
*
|
|
@@ -17,7 +17,7 @@ import { type InitStoreOptions, type SetState } from 'floppy-disk/vanilla';
|
|
|
17
17
|
export type MutationState<TData, TVariable, TError> = {
|
|
18
18
|
isPending: boolean;
|
|
19
19
|
} & ({
|
|
20
|
-
state:
|
|
20
|
+
state: "INITIAL";
|
|
21
21
|
isSuccess: false;
|
|
22
22
|
isError: false;
|
|
23
23
|
variable: undefined;
|
|
@@ -26,7 +26,7 @@ export type MutationState<TData, TVariable, TError> = {
|
|
|
26
26
|
error: undefined;
|
|
27
27
|
errorUpdatedAt: undefined;
|
|
28
28
|
} | {
|
|
29
|
-
state:
|
|
29
|
+
state: "SUCCESS";
|
|
30
30
|
isSuccess: true;
|
|
31
31
|
isError: false;
|
|
32
32
|
variable: TVariable;
|
|
@@ -35,7 +35,7 @@ export type MutationState<TData, TVariable, TError> = {
|
|
|
35
35
|
error: undefined;
|
|
36
36
|
errorUpdatedAt: undefined;
|
|
37
37
|
} | {
|
|
38
|
-
state:
|
|
38
|
+
state: "ERROR";
|
|
39
39
|
isSuccess: false;
|
|
40
40
|
isError: true;
|
|
41
41
|
variable: TVariable;
|
package/react/create-query.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InitStoreOptions, type SetState } from
|
|
1
|
+
import { type InitStoreOptions, type SetState } from "../vanilla.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Represents the state of a query.
|
|
4
4
|
*
|
|
@@ -25,7 +25,7 @@ export type QueryState<TData, TError> = {
|
|
|
25
25
|
isRetrying: boolean;
|
|
26
26
|
retryCount: number;
|
|
27
27
|
} & ({
|
|
28
|
-
state:
|
|
28
|
+
state: "INITIAL";
|
|
29
29
|
isSuccess: false;
|
|
30
30
|
isError: false;
|
|
31
31
|
data: undefined;
|
|
@@ -33,7 +33,7 @@ export type QueryState<TData, TError> = {
|
|
|
33
33
|
error: undefined;
|
|
34
34
|
errorUpdatedAt: undefined;
|
|
35
35
|
} | {
|
|
36
|
-
state:
|
|
36
|
+
state: "SUCCESS";
|
|
37
37
|
isSuccess: true;
|
|
38
38
|
isError: false;
|
|
39
39
|
data: TData;
|
|
@@ -41,7 +41,7 @@ export type QueryState<TData, TError> = {
|
|
|
41
41
|
error: undefined;
|
|
42
42
|
errorUpdatedAt: undefined;
|
|
43
43
|
} | {
|
|
44
|
-
state:
|
|
44
|
+
state: "ERROR";
|
|
45
45
|
isSuccess: false;
|
|
46
46
|
isError: true;
|
|
47
47
|
data: undefined;
|
|
@@ -49,7 +49,7 @@ export type QueryState<TData, TError> = {
|
|
|
49
49
|
error: TError;
|
|
50
50
|
errorUpdatedAt: number;
|
|
51
51
|
} | {
|
|
52
|
-
state:
|
|
52
|
+
state: "SUCCESS_BUT_REVALIDATION_ERROR";
|
|
53
53
|
isSuccess: true;
|
|
54
54
|
isError: false;
|
|
55
55
|
data: TData;
|
package/react/create-store.d.ts
CHANGED
package/react/create-stores.d.ts
CHANGED
package/react/use-mutation.d.ts
CHANGED
package/react/use-store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StoreApi } from
|
|
1
|
+
import { type StoreApi } from "../vanilla.ts";
|
|
2
2
|
type Path = Array<string | number | symbol>;
|
|
3
3
|
export declare const getValueByPath: (obj: any, path: Path) => any;
|
|
4
4
|
export declare const isPrefixPath: (candidatePrefix: Path, targetPath: Path) => boolean;
|
package/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export { useStoreState } from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export { createMutation, type MutationOptions, type MutationState, } from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./react/use-isomorphic-layout-effect.ts";
|
|
2
|
+
export { useStoreState } from "./react/use-store.ts";
|
|
3
|
+
export * from "./react/create-store.ts";
|
|
4
|
+
export * from "./react/create-stores.ts";
|
|
5
|
+
export * from "./react/create-query.ts";
|
|
6
|
+
export { createMutation, type MutationOptions, type MutationState, } from "./react/create-mutation.ts";
|
|
7
|
+
export * from "./react/use-mutation.ts";
|
package/vanilla.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./vanilla/basic.ts";
|
|
2
|
+
export * from "./vanilla/hash.ts";
|
|
3
|
+
export * from "./vanilla/store.ts";
|