@rkrupinski/stan 1.5.0 → 1.5.1-rc1
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 +1 -0
- package/dist/react.esm.js +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Stan
|
|
4
4
|
|
|
5
5
|
[](https://github.com/rkrupinski/stan/actions/workflows/ci.yml)
|
|
6
|
+

|
|
6
7
|

|
|
7
8
|
|
|
8
9
|
Minimal, type-safe state management
|
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 e,useContext as t,useMemo as n,useRef as o,useState as s,useEffect as c,useCallback as u}from"react";import{D as a,m as i,r as l,f as p}from"./store-D_uSq-w8.js";const m=e({store:a}),d=({store:e,children:t})=>{const o=n((()=>({store:e??i()})),[e]);return r(m.Provider,{value:o,children:t})},g=()=>t(m),y=r=>{const{store:e}=g(),t=r(e),n=o(t),[u,a]=s((()=>t.get()));let i=u;t!==n.current&&(i=t.get(),n.current=t,a(i));const l=o(new WeakMap);return l.current.has(t)||l.current.set(t,t.subscribe(a)),c((()=>{const r=l.current;return()=>{const e=r.get(t);e&&(e(),r.delete(t))}}),[t]),i},f=r=>{const{store:e}=g();return r(e).set},h=r=>[y(r),f(r)],v=r=>{const e=y(r),[t,n]=s({type:"loading"});return c((()=>{let r=!0;return n({type:"loading"}),e.then((e=>{r&&n({type:"ready",value:e})}),(e=>{r&&n({type:"error",reason:e})})),()=>{r=!1}}),[e]),t},b=r=>{const{store:e}=g(),t=r(e);return u((()=>{l(t)}),[t])},j=r=>{const{store:e}=g(),t=r(e);return u((()=>{p(t)}),[t])};export{d as StanProvider,f as useSetStanValue,h as useStan,g as useStanCtx,b as useStanRefresh,j as useStanReset,y 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}),n=()=>t.useContext(s),u=e=>{const{store:r}=n(),s=e(r),u=t.useRef(s),[o,a]=t.useState((()=>s.get()));let c=o;s!==u.current&&(c=s.get(),u.current=s,a(c));const l=t.useRef(new WeakMap);return l.current.has(s)||l.current.set(s,s.subscribe(a)),t.useEffect((()=>{const e=l.current;return()=>{const t=e.get(s);t&&(t(),e.delete(s))}}),[s]),c},o=e=>{const{store:t}=n();return e(t).set};exports.StanProvider=({store:n,children:u})=>{const o=t.useMemo((()=>({store:n??r.makeStore()})),[n]);return e.jsx(s.Provider,{value:o,children:u})},exports.useSetStanValue=o,exports.useStan=e=>[u(e),o(e)],exports.useStanCtx=n,exports.useStanRefresh=e=>{const{store:s}=n(),u=e(s);return t.useCallback((()=>{r.refresh(u)}),[u])},exports.useStanReset=e=>{const{store:s}=n(),u=e(s);return t.useCallback((()=>{r.reset(u)}),[u])},exports.useStanValue=u,exports.useStanValueAsync=e=>{const r=u(e),[s,n]=t.useState({type:"loading"});return t.useEffect((()=>{let e=!0;return n({type:"loading"}),r.then((t=>{e&&n({type:"ready",value:t})}),(t=>{e&&n({type:"error",reason:t})})),()=>{e=!1}}),[r]),s};
|