@rkrupinski/stan 1.4.0-rc1 → 1.5.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/dist/react.d.ts +3 -3
- package/dist/react.esm.js +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -13,15 +13,15 @@ export declare const useStanCtx: () => StanCtxType;
|
|
|
13
13
|
export declare const useStanValue: <T>(scopedState: Scoped<State<T>>) => T;
|
|
14
14
|
export declare const useSetStanValue: <T>(scopedState: Scoped<WritableState<T>>) => import("./types").SetterOrUpdater<T>;
|
|
15
15
|
export declare const useStan: <T>(scopedState: Scoped<WritableState<T>>) => readonly [T, import("./types").SetterOrUpdater<T>];
|
|
16
|
-
export type AsyncValue<T> = {
|
|
16
|
+
export type AsyncValue<T, E = unknown> = {
|
|
17
17
|
type: 'loading';
|
|
18
18
|
} | {
|
|
19
19
|
type: 'ready';
|
|
20
20
|
value: T;
|
|
21
21
|
} | {
|
|
22
22
|
type: 'error';
|
|
23
|
-
reason:
|
|
23
|
+
reason: E;
|
|
24
24
|
};
|
|
25
|
-
export declare const useStanValueAsync: <T>(scopedState: Scoped<State<PromiseLike<T>>>) => AsyncValue<T>;
|
|
25
|
+
export declare const useStanValueAsync: <T, E = unknown>(scopedState: Scoped<State<PromiseLike<T>>>) => AsyncValue<T, E>;
|
|
26
26
|
export declare const useStanRefresh: <T>(scopedState: Scoped<ReadonlyState<T>>) => () => void;
|
|
27
27
|
export declare const useStanReset: <T>(scopedState: Scoped<WritableState<T>>) => () => void;
|
package/dist/react.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as r}from"react/jsx-runtime";import{createContext as
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";import{createContext as t,useContext as e,useMemo as o,useRef as s,useState as n,useEffect as c,useCallback as u}from"react";import{D as a,m as i,r as m,f as p}from"./store-D_uSq-w8.js";const l=t({store:a}),d=({store:t,children:e})=>{const s=o((()=>({store:t??i()})),[t]);return r(l.Provider,{value:s,children:e})},y=()=>e(l),f=r=>{const{store:t}=y(),e=r(t),o=s(e),[u,a]=n((()=>e.get()));return c((()=>(e!==o.current&&(o.current=e,a(e.get())),e.subscribe(a))),[e]),u},g=r=>{const{store:t}=y();return r(t).set},h=r=>[f(r),g(r)],v=r=>{const t=f(r),[e,o]=n({type:"loading"});return c((()=>{let r=!0;return o({type:"loading"}),t.then((t=>{r&&o({type:"ready",value:t})}),(t=>{r&&o({type:"error",reason:t})})),()=>{r=!1}}),[t]),e},b=r=>{const{store:t}=y(),e=r(t);return u((()=>{m(e)}),[e])},j=r=>{const{store:t}=y(),e=r(t);return u((()=>{p(e)}),[e])};export{d as StanProvider,g as useSetStanValue,h as useStan,y as useStanCtx,b as useStanRefresh,j as useStanReset,f as useStanValue,v as useStanValueAsync};
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("./store-DiTSwUBS.js");const s=t.createContext({store:r.DEFAULT_STORE}),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("./store-DiTSwUBS.js");const s=t.createContext({store:r.DEFAULT_STORE}),u=()=>t.useContext(s),n=e=>{const{store:r}=u(),s=e(r),n=t.useRef(s),[o,a]=t.useState((()=>s.get()));return t.useEffect((()=>(s!==n.current&&(n.current=s,a(s.get())),s.subscribe(a))),[s]),o},o=e=>{const{store:t}=u();return e(t).set};exports.StanProvider=({store:u,children:n})=>{const o=t.useMemo((()=>({store:u??r.makeStore()})),[u]);return e.jsx(s.Provider,{value:o,children:n})},exports.useSetStanValue=o,exports.useStan=e=>[n(e),o(e)],exports.useStanCtx=u,exports.useStanRefresh=e=>{const{store:s}=u(),n=e(s);return t.useCallback((()=>{r.refresh(n)}),[n])},exports.useStanReset=e=>{const{store:s}=u(),n=e(s);return t.useCallback((()=>{r.reset(n)}),[n])},exports.useStanValue=n,exports.useStanValueAsync=e=>{const r=n(e),[s,u]=t.useState({type:"loading"});return t.useEffect((()=>{let e=!0;return u({type:"loading"}),r.then((t=>{e&&u({type:"ready",value:t})}),(t=>{e&&u({type:"error",reason:t})})),()=>{e=!1}}),[r]),s};
|