@rkrupinski/stan 1.0.0-rc11 → 1.0.0-rc13

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/index.js CHANGED
@@ -1 +1 @@
1
- import{s as e,i as t,R as s,d as a,a as c}from"./utils-D5tiXDeQ.js";export{r as refresh}from"./utils-D5tiXDeQ.js";class n{#e;#t;constructor(e){this.#e=new Map,this.#t=e}#s(){const e=this.#e.keys().next().value;void 0!==e&&this.#e.delete(e)}has(e){return this.#e.has(e)}get(e){if(!this.has(e))return;const t=this.#e.get(e);return this.#e.delete(e),this.#e.set(e,t),t}set(e,t){this.#e.has(e)?this.#e.delete(e):this.#e.size>=this.#t&&this.#s(),this.#e.set(e,t)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}}class h extends Map{}const i=e=>{switch(e.type){case"keep-all":return new h;case"most-recent":return new n(1);case"lru":return new n(e.maxSize);default:return e}},l=(e,{effects:s}={})=>{let a=!1,c=e;const r=new Set,n=new Set,h=(e=!1)=>s=>{c=t(s)?s(c):s,r.forEach((e=>e(c))),e||n.forEach((e=>e(c)))};return s?.forEach((e=>e({init(e){a||(c=e)},set:h(!0),onSet(e){n.add(e)}}))),a=!0,{get:()=>c,set:h(),subscribe:e=>(r.add(e),()=>{r.delete(e)})}},u=(s,a)=>{const c=i({type:"keep-all"});return r=>{const n=e(r);return c.has(n)||c.set(n,l(t(s)?s(r):s,a)),c.get(n)}},o=(e,{areValuesEqual:t=a}={})=>{let c,r=!1,n=!1;const h=new Set,i=new Set,l=new Set,u=e=>{let s=e.get();if(!i.has(e)){i.add(e);const a=e.subscribe((e=>{t(s,e)||(s=e,o(),d())}));l.add(a)}return s},o=()=>{c=e({get:u})},d=()=>{h.forEach((e=>e(c)))};return{get:()=>(r||(r=!0,o()),c),subscribe:e=>(0===h.size&&(n=!0),h.add(e),function(){h.delete(e),0===h.size&&(n=!1,l.forEach((e=>e())),l.clear(),i.clear())}),[s](){n?(o(),d()):r=!1}}},d=(t,{areValuesEqual:s=a,cachePolicy:r={type:"keep-all"}}={})=>{const n=i(r);return a=>{const r=e(a);if(!n.has(r)){const e=o(t(a),{areValuesEqual:s}),h=e.get.bind(e);e.get=()=>{const e=h();return c(e)&&e.then(void 0,(()=>{n.delete(r)})),e},n.set(r,e)}return n.get(r)}};export{l as atom,u as atomFamily,o as selector,d as selectorFamily};
1
+ import{s as e,i as t,R as s,d as a,a as c}from"./utils-D5tiXDeQ.js";export{r as refresh}from"./utils-D5tiXDeQ.js";class h{#e;#t;constructor(e){this.#e=new Map,this.#t=e}#s(){const e=this.#e.keys().next().value;void 0!==e&&this.#e.delete(e)}has(e){return this.#e.has(e)}get(e){if(!this.has(e))return;const t=this.#e.get(e);return this.#e.delete(e),this.#e.set(e,t),t}set(e,t){this.#e.has(e)?this.#e.delete(e):this.#e.size>=this.#t&&this.#s(),this.#e.set(e,t)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}}class n extends Map{}const i=e=>{switch(e.type){case"keep-all":return new n;case"most-recent":return new h(1);case"lru":return new h(e.maxSize);default:return e}},l=(e,{effects:s}={})=>{let a=!1,c=e;const r=new Set,h=new Set,n=(e=!1)=>s=>{c=t(s)?s(c):s,r.forEach((e=>e(c))),e||h.forEach((e=>e(c)))};return s?.forEach((e=>e({init(e){a||(c=e)},set:n(!0),onSet(e){h.add(e)}}))),a=!0,{get:()=>c,set:n(),subscribe:e=>(r.add(e),()=>{r.delete(e)})}},u=(s,a)=>{const c=i({type:"keep-all"});return r=>{const h=e(r);return c.has(h)||c.set(h,l(t(s)?s(r):s,a)),c.get(h)}},o=(e,{areValuesEqual:t=a}={})=>{let r,h=!1,n=!1;const i=new Set,l=new Set,u=new Set,o=e=>{let s=e.get();if(!l.has(e)){l.add(e);const a=e.subscribe((e=>{t(s,e)||(s=e,d(),f())}));u.add(a)}return s},d=()=>{r=e({get:o}),c(r)&&r.then(void 0,(()=>{h=!1}))},f=()=>{i.forEach((e=>e(r)))};return{get:()=>(h||(h=!0,d()),r),subscribe:e=>(0===i.size&&(n=!0),i.add(e),function(){i.delete(e),0===i.size&&(n=!1,u.forEach((e=>e())),u.clear(),l.clear())}),[s](){n?(d(),f()):h=!1}}},d=(t,{areValuesEqual:s=a,cachePolicy:c={type:"keep-all"}}={})=>{const r=i(c);return a=>{const c=e(a);return r.has(c)||r.set(c,o(t(a),{areValuesEqual:s})),r.get(c)}};export{l as atom,u as atomFamily,o as selector,d as selectorFamily};
package/dist/react.d.ts CHANGED
@@ -8,8 +8,8 @@ export type AsyncValue<T> = {
8
8
  type: 'error';
9
9
  reason: string;
10
10
  };
11
- export declare const useStan: <T>(state: WritableState<T>) => readonly [T, import("./state").SetterOrUpdater<T>];
12
11
  export declare const useStanValue: <T>(state: State<T>) => T;
12
+ export declare const useStan: <T>(state: WritableState<T>) => readonly [T, import("./state").SetterOrUpdater<T>];
13
13
  export declare const useStanValueAsync: <T>(state: ReadonlyState<PromiseLike<T>>) => AsyncValue<T>;
14
14
  export declare const useSetStanValue: <T>(state: WritableState<T>) => import("./state").SetterOrUpdater<T>;
15
15
  export declare const useStanRefresher: (state: ReadonlyState<any>) => () => void;
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{useSyncExternalStore as e,useCallback as t,useState as r,useEffect as s}from"react";import{r as o}from"./utils-D5tiXDeQ.js";const n=t=>[e(t.subscribe,t.get),t.set],a=t=>e(t.subscribe,t.get),i=t=>{const o=e(t.subscribe,t.get),[n,a]=r({type:"loading"});return s((()=>{let e=!0;return"loading"!==n.type&&a({type:"loading"}),o.then((t=>{e&&a({type:"ready",value:t})}),(t=>{e&&a({type:"error",reason:t?.message??"unknown"})})),()=>{e=!1}}),[o]),n},p=e=>e.set,u=e=>t((()=>{o(e)}),[e]);export{p as useSetStanValue,n as useStan,u as useStanRefresher,a as useStanValue,i as useStanValueAsync};
1
+ import{useCallback as e,useRef as t,useState as r,useEffect as n}from"react";import{r as o}from"./utils-D5tiXDeQ.js";const s=e=>{const o=t(e),[s,a]=r(e.get());return n((()=>(e!==o.current&&(a(e.get()),o.current=e),e.subscribe(a))),[e]),s},a=e=>[s(e),e.set],u=e=>{const t=s(e),[o,a]=r({type:"loading"});return n((()=>{let e=!0;return"loading"!==o.type&&a({type:"loading"}),t.then((t=>{e&&a({type:"ready",value:t})}),(t=>{e&&a({type:"error",reason:t?.message??"unknown"})})),()=>{e=!1}}),[t]),o},p=e=>e.set,c=t=>e((()=>{o(t)}),[t]);export{p as useSetStanValue,a as useStan,c as useStanRefresher,s as useStanValue,u as useStanValueAsync};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rkrupinski/stan",
3
3
  "description": "Minimal, type-safe state management",
4
- "version": "1.0.0-rc11",
4
+ "version": "1.0.0-rc13",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
7
7
  "./react": "./dist/react.js"