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 CHANGED
@@ -1,9 +1,12 @@
1
1
  # FloppyDisk.ts 💾
2
2
 
3
- A lightweight, simple, and powerful state management library.
3
+ A unified state model for **sync & async** data.
4
4
 
5
- This library was highly-inspired by [Zustand](https://www.npmjs.com/package/zustand) and [TanStack-Query](https://tanstack.com/query), they're awesome state manager.
6
- FloppyDisk provides a very similar developer experience (DX), while introducing additional features and a smaller bundle size.
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 'floppy-disk/react';
24
+ import { createStore } from "floppy-disk/react";
22
25
 
23
26
  const useDigimon = createStore({
24
27
  age: 7,
25
- level: 'Rookie',
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 = ['In-Training', 'Rookie', 'Champion', 'Ultimate'];
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('Already at ultimate level');
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('New state:', state);
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('First subscriber! We’re officially popular 🎉');
94
+ console.log("First subscriber! We’re officially popular 🎉");
92
95
  },
93
96
  onSubscribe: () => {
94
- console.log('New subscriber joined. Welcome aboard 🫡');
97
+ console.log("New subscriber joined. Welcome aboard 🫡");
95
98
  },
96
99
  onUnsubscribe: () => {
97
- console.log('Subscriber left... was it something I said? 😭');
100
+ console.log("Subscriber left... was it something I said? 😭");
98
101
  },
99
102
  onLastUnsubscribe: () => {
100
- console.log('Everyone left. Guess I’ll just exist quietly now...');
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 'floppy-disk/react';
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 === 'INITIAL') return <div>Loading...</div>;
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 '../utils';
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 === 'INITIAL') return <div>Loading...</div>;
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 === 'INITIAL') return <div>Loading...</div>;
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 'floppy-disk/vanilla';
1
+ export * from "./vanilla.ts";
@@ -1,4 +1,4 @@
1
- import { type InitStoreOptions, type SetState } from 'floppy-disk/vanilla';
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: 'INITIAL';
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: 'SUCCESS';
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: 'ERROR';
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 'floppy-disk/vanilla';
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: 'INITIAL';
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: 'SUCCESS';
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: 'ERROR';
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: 'SUCCESS_BUT_REVALIDATION_ERROR';
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 InitStoreOptions } from 'floppy-disk/vanilla';
1
+ import { type InitStoreOptions } from "../vanilla.ts";
2
2
  /**
3
3
  * Creates a single store with a bound React hook.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { type InitStoreOptions } from 'floppy-disk/vanilla';
1
+ import { type InitStoreOptions } from "../vanilla.ts";
2
2
  /**
3
3
  * Creates a factory for multiple stores identified by a key.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect } from 'react';
1
+ import { useLayoutEffect } from "react";
2
2
  /**
3
3
  * Does exactly same as `useLayoutEffect`.\
4
4
  * It will use `useEffect` in **server-side** to prevent warning when executed on server-side.
@@ -1,4 +1,4 @@
1
- import { type MutationOptions, type MutationState } from './create-mutation.mjs';
1
+ import { type MutationOptions, type MutationState } from "./create-mutation.ts";
2
2
  /**
3
3
  * A hook for managing async mutation state.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { type StoreApi } from 'floppy-disk/vanilla';
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 './react/use-isomorphic-layout-effect.mjs';
2
- export { useStoreState } from './react/use-store.mjs';
3
- export * from './react/create-store.mjs';
4
- export * from './react/create-stores.mjs';
5
- export * from './react/create-query.mjs';
6
- export { createMutation, type MutationOptions, type MutationState, } from './react/create-mutation.mjs';
7
- export * from './react/use-mutation.mjs';
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 './vanilla/basic.mjs';
2
- export * from './vanilla/hash.mjs';
3
- export * from './vanilla/store.mjs';
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 'floppy-disk/vanilla';
1
+ export * from "./vanilla.ts";
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "description": "Lightweight, simple, and powerful state management library",
3
+ "description": "Lightweight unified state management for sync and async data.",
4
4
  "private": false,
5
- "version": "3.1.0",
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 'floppy-disk/vanilla';
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: 'INITIAL';
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: 'SUCCESS';
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: 'ERROR';
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 'floppy-disk/vanilla';
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: 'INITIAL';
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: 'SUCCESS';
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: 'ERROR';
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: 'SUCCESS_BUT_REVALIDATION_ERROR';
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 InitStoreOptions } from 'floppy-disk/vanilla';
1
+ import { type InitStoreOptions } from "../vanilla.ts";
2
2
  /**
3
3
  * Creates a single store with a bound React hook.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { type InitStoreOptions } from 'floppy-disk/vanilla';
1
+ import { type InitStoreOptions } from "../vanilla.ts";
2
2
  /**
3
3
  * Creates a factory for multiple stores identified by a key.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect } from 'react';
1
+ import { useLayoutEffect } from "react";
2
2
  /**
3
3
  * Does exactly same as `useLayoutEffect`.\
4
4
  * It will use `useEffect` in **server-side** to prevent warning when executed on server-side.
@@ -1,4 +1,4 @@
1
- import { type MutationOptions, type MutationState } from './create-mutation';
1
+ import { type MutationOptions, type MutationState } from "./create-mutation.ts";
2
2
  /**
3
3
  * A hook for managing async mutation state.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { type StoreApi } from 'floppy-disk/vanilla';
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 './react/use-isomorphic-layout-effect';
2
- export { useStoreState } from './react/use-store';
3
- export * from './react/create-store';
4
- export * from './react/create-stores';
5
- export * from './react/create-query';
6
- export { createMutation, type MutationOptions, type MutationState, } from './react/create-mutation';
7
- export * from './react/use-mutation';
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 './vanilla/basic';
2
- export * from './vanilla/hash';
3
- export * from './vanilla/store';
1
+ export * from "./vanilla/basic.ts";
2
+ export * from "./vanilla/hash.ts";
3
+ export * from "./vanilla/store.ts";