@kdeveloper/kvark 0.17.0 → 1.0.0
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 +158 -115
- package/dist/family.d.ts +16 -13
- package/dist/family.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/preact/index.d.ts +4 -4
- package/dist/preact/index.js +7 -33
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +7 -33
- package/dist/react/index.js.map +1 -1
- package/dist/{store-DSvJVL5c.js → store-Cq_V-puR.js} +178 -56
- package/dist/store-Cq_V-puR.js.map +1 -0
- package/dist/{types-CHPLxaFJ.d.ts → types-D8ep-ydI.d.ts} +58 -26
- package/dist/use-atom-value-BhGvD9Vf.js +35 -0
- package/dist/use-atom-value-BhGvD9Vf.js.map +1 -0
- package/dist/vue/index.d.ts +4 -4
- package/dist/vue/index.js +9 -9
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/store-DSvJVL5c.js.map +0 -1
package/dist/family.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as InfinityAtomFamily, D as InfiniteData, E as infinityAtomFamily, M as atom, O as InfinityAtomOptions, S as mutation, T as InfinityFamilyAtom, _ as StoreClient, a as AtomState, b as createStore, d as StalePolicy, f as WritableAtom, g as Store, h as RegisteredContext, i as AtomContext, k as infinityAtom, l as MutationContext, m as Register, o as AtomValue, p as WritableAtomContext, r as AtomConfig, s as DependencyEntry, t as Atom, u as RetryDelay, v as StoreInspection, w as InfinityAtomFamilyOptions, x as Mutation, y as StoreOptions } from "./types-D8ep-ydI.js";
|
|
2
2
|
|
|
3
3
|
//#region src/internal/family-batch-schedulers.d.ts
|
|
4
4
|
type BatchSchedulerContext = {
|
|
@@ -30,18 +30,18 @@ type AtomFamilyBaseOptions<Param, Key = Param> = {
|
|
|
30
30
|
lruSize?: number;
|
|
31
31
|
debugLabel?: string;
|
|
32
32
|
/**
|
|
33
|
-
* If `false`, the store will not auto-invalidate the atom after a successful `
|
|
34
|
-
* Use this when the family's `
|
|
35
|
-
* `ctx.setOptimisticValue` and there is no need to re-run `
|
|
36
|
-
* Defaults to `true` (matches the typical CRUD pattern: `
|
|
37
|
-
* `
|
|
33
|
+
* If `false`, the store will not auto-invalidate the atom after a successful `write`.
|
|
34
|
+
* Use this when the family's `write` writes the authoritative next value via
|
|
35
|
+
* `ctx.setOptimisticValue` and there is no need to re-run `read` to converge.
|
|
36
|
+
* Defaults to `true` (matches the typical CRUD pattern: `write` mutates the server,
|
|
37
|
+
* `read` then refetches the canonical state).
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
invalidateAfterWrite?: boolean;
|
|
40
40
|
/**
|
|
41
41
|
* Optional function to derive a stable cache key from `param`.
|
|
42
42
|
* Use when `Param` is an object and you want equality-by-value semantics.
|
|
43
43
|
* The returned key is used for all cache operations (get, set, LRU, invalidate, remove).
|
|
44
|
-
* The original `param` is still passed to `
|
|
44
|
+
* The original `param` is still passed to `read`, `write`, and `dependencies`.
|
|
45
45
|
*
|
|
46
46
|
* For plain objects/arrays you can use `stableFamilyKey` from `@kdeveloper/kvark/family`.
|
|
47
47
|
* Treat the param object as immutable after the first call — `stableFamilyKey` memoises
|
|
@@ -51,8 +51,8 @@ type AtomFamilyBaseOptions<Param, Key = Param> = {
|
|
|
51
51
|
};
|
|
52
52
|
type AtomFamilyGetOptions<Param, Value, Deps extends Record<string, DependencyEntry>, Args extends readonly unknown[], Key = Param> = AtomFamilyBaseOptions<Param, Key> & {
|
|
53
53
|
dependencies?: (param: Param) => Deps;
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
read: (param: Param) => (ctx: AtomContext<Deps>) => Promise<Value>;
|
|
55
|
+
write?: (param: Param) => (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;
|
|
56
56
|
batch?: never;
|
|
57
57
|
};
|
|
58
58
|
type AtomFamilyBatchOptions<Param, Value, Deps extends Record<string, DependencyEntry>, Key = Param> = AtomFamilyBaseOptions<Param, Key> & {
|
|
@@ -66,15 +66,18 @@ type AtomFamilyBatchOptions<Param, Value, Deps extends Record<string, Dependency
|
|
|
66
66
|
fetch: (input: BatchFetchInput<Param, Key, Deps>) => Promise<Map<Key, Value>>;
|
|
67
67
|
scheduler?: BatchScheduler;
|
|
68
68
|
};
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
read?: never;
|
|
70
|
+
write?: never;
|
|
71
71
|
};
|
|
72
72
|
type AtomFamilyOptions<Param, Value, Deps extends Record<string, DependencyEntry>, Args extends readonly unknown[], Key = Param> = AtomFamilyGetOptions<Param, Value, Deps, Args, Key> | AtomFamilyBatchOptions<Param, Value, Deps, Key>;
|
|
73
73
|
interface AtomFamily<Param, Value, Key = Param> {
|
|
74
74
|
(param: Param): Atom<Value>;
|
|
75
75
|
invalidate(param: Param): void;
|
|
76
76
|
invalidateAll(): void;
|
|
77
|
+
has(param: Param): boolean;
|
|
78
|
+
peek(param: Param): Atom<Value> | undefined;
|
|
77
79
|
remove(param: Param): void;
|
|
80
|
+
clear(): void;
|
|
78
81
|
getCache(): ReadonlyMap<Key, Atom<Value>>;
|
|
79
82
|
}
|
|
80
83
|
declare function atomFamily<Param, Value, Deps extends Record<string, DependencyEntry> = Record<never, never>, Args extends readonly unknown[] = readonly [], Key = Param>(options: AtomFamilyOptions<Param, Value, Deps, Args, Key>): AtomFamily<Param, Value, Key>;
|
|
@@ -93,5 +96,5 @@ declare function atomFamily<Param, Value, Deps extends Record<string, Dependency
|
|
|
93
96
|
*/
|
|
94
97
|
declare function stableFamilyKey(value: unknown): string;
|
|
95
98
|
//#endregion
|
|
96
|
-
export { type Atom, type AtomConfig, type AtomContext, type AtomFamily, type AtomFamilyBatchOptions, type AtomFamilyGetOptions, type AtomFamilyOptions, type AtomState, type AtomValue, type BatchFetchInput, type BatchScheduler, type BatchSchedulerContext, type InfiniteData, type InfinityAtomFamily, type InfinityAtomFamilyOptions, type InfinityAtomOptions, type InfinityFamilyAtom, type Mutation, type MutationContext, type Register, type RegisteredContext, type StalePolicy, type WritableAtom, atom, atomFamily, createStore, infinityAtom, infinityAtomFamily, maxBatchSizeScheduler, microtaskScheduler, mutation, stableFamilyKey, windowScheduler, windowedFiniteBatchScheduler };
|
|
99
|
+
export { type Atom, type AtomConfig, type AtomContext, type AtomFamily, type AtomFamilyBatchOptions, type AtomFamilyGetOptions, type AtomFamilyOptions, type AtomState, type AtomValue, type BatchFetchInput, type BatchScheduler, type BatchSchedulerContext, type InfiniteData, type InfinityAtomFamily, type InfinityAtomFamilyOptions, type InfinityAtomOptions, type InfinityFamilyAtom, type Mutation, type MutationContext, type Register, type RegisteredContext, type StalePolicy, type Store, type StoreClient, type StoreInspection, type StoreOptions, type WritableAtom, atom, atomFamily, createStore, infinityAtom, infinityAtomFamily, maxBatchSizeScheduler, microtaskScheduler, mutation, stableFamilyKey, windowScheduler, windowedFiniteBatchScheduler };
|
|
97
100
|
//# sourceMappingURL=family.d.ts.map
|
package/dist/family.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as microtaskScheduler, c as infinityAtomFamily, i as maxBatchSizeScheduler, l as infinityAtom, n as mutation, o as windowScheduler, r as atomFamily, s as windowedFiniteBatchScheduler, t as createStore, u as atom } from "./store-
|
|
1
|
+
import { a as microtaskScheduler, c as infinityAtomFamily, i as maxBatchSizeScheduler, l as infinityAtom, n as mutation, o as windowScheduler, r as atomFamily, s as windowedFiniteBatchScheduler, t as createStore, u as atom } from "./store-Cq_V-puR.js";
|
|
2
2
|
//#region src/internal/stable-family-key.ts
|
|
3
3
|
/**
|
|
4
4
|
* Produces a deterministic string key for plain-object/array/primitive values.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { Atom, AtomArgs, AtomConfig, AtomContext, AtomState, AtomValue, InfiniteData, InfinityAtomFamily, InfinityAtomFamilyOptions, InfinityAtomOptions, InfinityFamilyAtom, IsWritable, Mutation, MutationContext, Register, RegisteredContext, RetryDelay, SimpleAtomOptions,
|
|
1
|
+
import { A as SimpleAtomOptions, C as InfinityAtomFamily, D as InfiniteData, E as infinityAtomFamily, M as atom, O as InfinityAtomOptions, S as mutation, T as InfinityFamilyAtom, _ as StoreClient, a as AtomState, b as createStore, c as IsWritable, d as StalePolicy, f as WritableAtom, g as Store, h as RegisteredContext, i as AtomContext, j as SimpleAtomWriteArg, k as infinityAtom, l as MutationContext, m as Register, n as AtomArgs, o as AtomValue, p as WritableAtomContext, r as AtomConfig, t as Atom, u as RetryDelay, v as StoreInspection, w as InfinityAtomFamilyOptions, x as Mutation, y as StoreOptions } from "./types-D8ep-ydI.js";
|
|
2
|
+
export { Atom, AtomArgs, AtomConfig, AtomContext, AtomState, AtomValue, InfiniteData, InfinityAtomFamily, InfinityAtomFamilyOptions, InfinityAtomOptions, InfinityFamilyAtom, IsWritable, Mutation, MutationContext, Register, RegisteredContext, RetryDelay, SimpleAtomOptions, SimpleAtomWriteArg, StalePolicy, Store, StoreClient, StoreInspection, StoreOptions, WritableAtom, WritableAtomContext, atom, createStore, infinityAtom, infinityAtomFamily, mutation };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as infinityAtomFamily, l as infinityAtom, n as mutation, t as createStore, u as atom } from "./store-
|
|
1
|
+
import { c as infinityAtomFamily, l as infinityAtom, n as mutation, t as createStore, u as atom } from "./store-Cq_V-puR.js";
|
|
2
2
|
export { atom, createStore, infinityAtom, infinityAtomFamily, mutation };
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as StoreClient, f as WritableAtom, g as Store, t as Atom,
|
|
1
|
+
import { _ as StoreClient, f as WritableAtom, g as Store, t as Atom, x as Mutation } from "../types-D8ep-ydI.js";
|
|
2
2
|
import { ComponentChildren, VNode } from "preact";
|
|
3
3
|
|
|
4
4
|
//#region src/preact/provider.d.ts
|
|
@@ -23,8 +23,8 @@ declare function useAtomValue<V>(atom: Atom<V>, opts: {
|
|
|
23
23
|
observe: true;
|
|
24
24
|
}): ObservedValue<V>;
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/preact/use-
|
|
27
|
-
declare function
|
|
26
|
+
//#region src/preact/use-apply-atom.d.ts
|
|
27
|
+
declare function useApplyAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): (...args: A) => Promise<void>;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/preact/use-mutation.d.ts
|
|
30
30
|
declare function useMutation<Args extends readonly unknown[]>(mutation: Mutation<Args>): (...args: Args) => Promise<void>;
|
|
@@ -38,5 +38,5 @@ declare function useAtomContext<R>(callback: (ctx: StoreClient) => Promise<R>):
|
|
|
38
38
|
//#region src/preact/use-stable-fn.d.ts
|
|
39
39
|
declare function useStableFn<Args extends unknown[], R>(fn: (...args: Args) => R): (...args: Args) => R;
|
|
40
40
|
//#endregion
|
|
41
|
-
export { Provider, useAtom, useAtomContext, useAtomValue, useMutation,
|
|
41
|
+
export { Provider, useApplyAtom, useAtom, useAtomContext, useAtomValue, useMutation, useStableFn, useStore };
|
|
42
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/preact/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as getAtomValueResult } from "../use-atom-value-BhGvD9Vf.js";
|
|
2
2
|
import { createContext } from "preact";
|
|
3
3
|
import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
4
4
|
import { jsx } from "preact/jsx-runtime";
|
|
@@ -63,39 +63,13 @@ function useAtomValue(atom, opts) {
|
|
|
63
63
|
const initialRenderRef = useRef(true);
|
|
64
64
|
const isInitialRender = initialRenderRef.current;
|
|
65
65
|
initialRenderRef.current = false;
|
|
66
|
-
|
|
67
|
-
if (snapshot.status === "pending") throw store.resolve(atom);
|
|
68
|
-
if (snapshot.status === "stale") {
|
|
69
|
-
if (stalePolicy === "suspend") throw store.resolve(atom);
|
|
70
|
-
store.resolve(atom);
|
|
71
|
-
if (opts?.observe === true) return {
|
|
72
|
-
value: snapshot.value,
|
|
73
|
-
isStale: true,
|
|
74
|
-
error: void 0
|
|
75
|
-
};
|
|
76
|
-
return snapshot.value;
|
|
77
|
-
}
|
|
78
|
-
if (snapshot.status === "error") {
|
|
79
|
-
if (opts?.observe === true && snapshot.value !== void 0) return {
|
|
80
|
-
value: snapshot.value,
|
|
81
|
-
isStale: false,
|
|
82
|
-
error: snapshot.error
|
|
83
|
-
};
|
|
84
|
-
if (isInitialRender) store.resolve(atom);
|
|
85
|
-
throw snapshot.error;
|
|
86
|
-
}
|
|
87
|
-
if (opts?.observe === true) return {
|
|
88
|
-
value: snapshot.value,
|
|
89
|
-
isStale: false,
|
|
90
|
-
error: void 0
|
|
91
|
-
};
|
|
92
|
-
return snapshot.value;
|
|
66
|
+
return getAtomValueResult(store, atom, snapshot, opts?.observe === true, isInitialRender);
|
|
93
67
|
}
|
|
94
68
|
//#endregion
|
|
95
|
-
//#region src/preact/use-
|
|
96
|
-
function
|
|
69
|
+
//#region src/preact/use-apply-atom.ts
|
|
70
|
+
function useApplyAtom(atom) {
|
|
97
71
|
const store = useStore();
|
|
98
|
-
return useCallback((...args) => store.
|
|
72
|
+
return useCallback((...args) => store.apply(atom, ...args), [store, atom]);
|
|
99
73
|
}
|
|
100
74
|
//#endregion
|
|
101
75
|
//#region src/preact/use-mutation.ts
|
|
@@ -106,7 +80,7 @@ function useMutation(mutation) {
|
|
|
106
80
|
//#endregion
|
|
107
81
|
//#region src/preact/use-atom.ts
|
|
108
82
|
function useAtom(atom) {
|
|
109
|
-
return [useAtomValue(atom),
|
|
83
|
+
return [useAtomValue(atom), useApplyAtom(atom)];
|
|
110
84
|
}
|
|
111
85
|
//#endregion
|
|
112
86
|
//#region src/preact/use-atom-context.ts
|
|
@@ -115,6 +89,6 @@ function useAtomContext(callback) {
|
|
|
115
89
|
return useCallback(() => callback(store.getClient()), [store, callback]);
|
|
116
90
|
}
|
|
117
91
|
//#endregion
|
|
118
|
-
export { Provider, useAtom, useAtomContext, useAtomValue, useMutation,
|
|
92
|
+
export { Provider, useApplyAtom, useAtom, useAtomContext, useAtomValue, useMutation, useStableFn, useStore };
|
|
119
93
|
|
|
120
94
|
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/preact/provider.tsx","../../src/preact/use-sync-external-store.ts","../../src/preact/use-stable-fn.ts","../../src/preact/use-atom-value.ts","../../src/preact/use-
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/preact/provider.tsx","../../src/preact/use-sync-external-store.ts","../../src/preact/use-stable-fn.ts","../../src/preact/use-atom-value.ts","../../src/preact/use-apply-atom.ts","../../src/preact/use-mutation.ts","../../src/preact/use-atom.ts","../../src/preact/use-atom-context.ts"],"mappings":";;;;;;AAKA,MAAM,eAAe,cAA4B,KAAK;AAOtD,SAAgB,SAAS,EAAE,OAAO,YAAkC;CAClE,OAAO,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAQ;EAAiC,CAAA;;AAGhF,SAAgB,WAAkB;CAChC,MAAM,QAAQ,WAAW,aAAa;CACtC,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,4CAA4C;CAE9D,OAAO;;;;ACdT,SAAS,kBAAqB,MAAiC;CAC7D,IAAI;EACF,OAAO,CAAC,OAAO,GAAG,KAAK,QAAQ,KAAK,cAAc,CAAC;SAC7C;EACN,OAAO;;;AAIX,SAAgB,qBACd,WACA,aACG;CACH,MAAM,QAAQ,aAAa;CAE3B,MAAM,CAAC,EAAE,aAAa,eAAe,gBAAgB,EACnD,WAAW;EAAE,QAAQ;EAAO,cAAc;EAAa,EACxD,EAAE;CAEH,sBAAsB;EACpB,UAA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AU;CACxB,OAAO,kBAA8B,SAAS,MAAM,WAAW,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as StoreClient, f as WritableAtom, g as Store, t as Atom,
|
|
1
|
+
import { _ as StoreClient, f as WritableAtom, g as Store, t as Atom, x as Mutation } from "../types-D8ep-ydI.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/react/provider.d.ts
|
|
@@ -23,8 +23,8 @@ declare function useAtomValue<V>(atom: Atom<V>, opts: {
|
|
|
23
23
|
observe: true;
|
|
24
24
|
}): ObservedValue<V>;
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/react/use-
|
|
27
|
-
declare function
|
|
26
|
+
//#region src/react/use-apply-atom.d.ts
|
|
27
|
+
declare function useApplyAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): (...args: A) => Promise<void>;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/react/use-mutation.d.ts
|
|
30
30
|
declare function useMutation<Args extends readonly unknown[]>(mutation: Mutation<Args>): (...args: Args) => Promise<void>;
|
|
@@ -38,5 +38,5 @@ declare function useAtomContext<R>(callback: (ctx: StoreClient) => Promise<R>):
|
|
|
38
38
|
//#region src/react/use-stable-fn.d.ts
|
|
39
39
|
declare function useStableFn<Args extends unknown[], R>(fn: (...args: Args) => R): (...args: Args) => R;
|
|
40
40
|
//#endregion
|
|
41
|
-
export { Provider, useAtom, useAtomContext, useAtomValue, useMutation,
|
|
41
|
+
export { Provider, useApplyAtom, useAtom, useAtomContext, useAtomValue, useMutation, useStableFn, useStore };
|
|
42
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as getAtomValueResult } from "../use-atom-value-BhGvD9Vf.js";
|
|
2
2
|
import { createContext, useCallback, useContext, useRef, useSyncExternalStore } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/provider.tsx
|
|
@@ -29,39 +29,13 @@ function useAtomValue(atom, opts) {
|
|
|
29
29
|
const initialRenderRef = useRef(true);
|
|
30
30
|
const isInitialRender = initialRenderRef.current;
|
|
31
31
|
initialRenderRef.current = false;
|
|
32
|
-
|
|
33
|
-
if (snapshot.status === "pending") throw store.resolve(atom);
|
|
34
|
-
if (snapshot.status === "stale") {
|
|
35
|
-
if (stalePolicy === "suspend") throw store.resolve(atom);
|
|
36
|
-
store.resolve(atom);
|
|
37
|
-
if (opts?.observe === true) return {
|
|
38
|
-
value: snapshot.value,
|
|
39
|
-
isStale: true,
|
|
40
|
-
error: void 0
|
|
41
|
-
};
|
|
42
|
-
return snapshot.value;
|
|
43
|
-
}
|
|
44
|
-
if (snapshot.status === "error") {
|
|
45
|
-
if (opts?.observe === true && snapshot.value !== void 0) return {
|
|
46
|
-
value: snapshot.value,
|
|
47
|
-
isStale: false,
|
|
48
|
-
error: snapshot.error
|
|
49
|
-
};
|
|
50
|
-
if (isInitialRender) store.resolve(atom);
|
|
51
|
-
throw snapshot.error;
|
|
52
|
-
}
|
|
53
|
-
if (opts?.observe === true) return {
|
|
54
|
-
value: snapshot.value,
|
|
55
|
-
isStale: false,
|
|
56
|
-
error: void 0
|
|
57
|
-
};
|
|
58
|
-
return snapshot.value;
|
|
32
|
+
return getAtomValueResult(store, atom, snapshot, opts?.observe === true, isInitialRender);
|
|
59
33
|
}
|
|
60
34
|
//#endregion
|
|
61
|
-
//#region src/react/use-
|
|
62
|
-
function
|
|
35
|
+
//#region src/react/use-apply-atom.ts
|
|
36
|
+
function useApplyAtom(atom) {
|
|
63
37
|
const store = useStore();
|
|
64
|
-
return useCallback((...args) => store.
|
|
38
|
+
return useCallback((...args) => store.apply(atom, ...args), [store, atom]);
|
|
65
39
|
}
|
|
66
40
|
//#endregion
|
|
67
41
|
//#region src/react/use-mutation.ts
|
|
@@ -72,7 +46,7 @@ function useMutation(mutation) {
|
|
|
72
46
|
//#endregion
|
|
73
47
|
//#region src/react/use-atom.ts
|
|
74
48
|
function useAtom(atom) {
|
|
75
|
-
return [useAtomValue(atom),
|
|
49
|
+
return [useAtomValue(atom), useApplyAtom(atom)];
|
|
76
50
|
}
|
|
77
51
|
//#endregion
|
|
78
52
|
//#region src/react/use-atom-context.ts
|
|
@@ -81,6 +55,6 @@ function useAtomContext(callback) {
|
|
|
81
55
|
return useCallback(() => callback(store.getClient()), [store, callback]);
|
|
82
56
|
}
|
|
83
57
|
//#endregion
|
|
84
|
-
export { Provider, useAtom, useAtomContext, useAtomValue, useMutation,
|
|
58
|
+
export { Provider, useApplyAtom, useAtom, useAtomContext, useAtomValue, useMutation, useStableFn, useStore };
|
|
85
59
|
|
|
86
60
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-stable-fn.ts","../../src/react/use-atom-value.ts","../../src/react/use-
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-stable-fn.ts","../../src/react/use-atom-value.ts","../../src/react/use-apply-atom.ts","../../src/react/use-mutation.ts","../../src/react/use-atom.ts","../../src/react/use-atom-context.ts"],"mappings":";;;;AAGA,MAAM,eAAe,cAA4B,KAAK;AAOtD,SAAgB,SAAS,EAAE,OAAO,YAAsC;CACtE,OAAO,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAQ;EAAiC,CAAA;;AAGhF,SAAgB,WAAkB;CAChC,MAAM,QAAQ,WAAW,aAAa;CACtC,IAAI,SAAS,MACX,MAAM,IAAI,MAAM,4CAA4C;CAE9D,OAAO;;;;ACjBT,SAAgB,YACd,IACsB;CACtB,MAAM,MAAM,OAAO,GAAG;CACtB,IAAI,UAAU;CAEd,OAAO,aAAa,GAAG,SAAe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