@rkrupinski/stan 1.0.0-rc9 → 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 CHANGED
@@ -2,4 +2,23 @@
2
2
 
3
3
  [![CI](https://github.com/rkrupinski/stan/actions/workflows/ci.yml/badge.svg)](https://github.com/rkrupinski/stan/actions/workflows/ci.yml)
4
4
 
5
- Minimalistic state management
5
+ Minimal, type-safe state management
6
+
7
+ - [Website](https://rkrupinski.github.io/stan)
8
+ - [API docs](https://rkrupinski.github.io/stan/docs/api)
9
+ - [Examples](https://github.com/rkrupinski/stan/tree/master/packages/examples)
10
+
11
+ ```tsx
12
+ import { atom } from '@rkrupinski/stan';
13
+ import { useStanValue } from '@rkrupinski/stan/react';
14
+
15
+ const salary = atom(21);
16
+ const bonus = atom(37);
17
+ const total = selector(({ get }) => get(salary) + get(bonus));
18
+
19
+ const TotalSalary = () => {
20
+ const value = useStanValue(total);
21
+
22
+ return <small>{value}</small>;
23
+ };
24
+ ```
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{s as e,R as t,d as s}from"./utils-BY8H9TPH.js";export{r as refresh}from"./utils-BY8H9TPH.js";class c{#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 a extends Map{}const n=e=>{switch(e.type){case"keep-all":return new a;case"most-recent":return new c(1);case"lru":return new c(e.maxSize);default:return e}},h=(e,{effects:t}={})=>{let s=!1,c=e;const a=new Set,r=new Set,n=(e=!1)=>t=>{c=t instanceof Function?t(c):t,a.forEach((e=>e(c))),e||r.forEach((e=>e(c)))};return t?.forEach((e=>e({init(e){s||(c=e)},set:n(!0),onSet(e){r.add(e)}}))),s=!0,{get:()=>c,set:n(),subscribe:e=>(a.add(e),()=>{a.delete(e)})}},i=(t,s)=>{const c=n({type:"keep-all"});return a=>{const r=e(a);return c.has(r)||c.set(r,h(t instanceof Function?t(a):t,s)),c.get(r)}},l=(e,{areValuesEqual:c=s}={})=>{let a,r=!1,n=!1;const h=new Set,i=new Set,l=new Set,u=e=>{let t=e.get();if(!i.has(e)){i.add(e);const s=e.subscribe((e=>{c(t,e)||(t=e,o(),d())}));l.add(s)}return t},o=()=>{a=e({get:u})},d=()=>{h.forEach((e=>e(a)))};return{get:()=>(r||(r=!0,o()),a),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())}),[t](){n?(o(),d()):r=!1}}},u=(t,{areValuesEqual:c=s,cachePolicy:a={type:"keep-all"}}={})=>{const r=n(a);return s=>{const a=e(s);return r.has(a)||r.set(a,l(t(s),{areValuesEqual:c})),r.get(a)}};export{h as atom,i as atomFamily,l as selector,u 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/misc.d.ts CHANGED
@@ -5,3 +5,5 @@ type Json = string | number | boolean | null | {
5
5
  export type SerializableParam = Json;
6
6
  export declare const REFRESH_TAG: unique symbol;
7
7
  export declare const dejaVu: <T>(a: T, b: T) => boolean;
8
+ export declare const isFunction: (candidate: any) => candidate is (...args: any[]) => any;
9
+ export declare const isPromiseLike: (candidate: any) => candidate is PromiseLike<any>;
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-BY8H9TPH.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};
@@ -0,0 +1 @@
1
+ function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r,e;var n=t(e?r:(e=1,r=function(t,r){r||(r={}),"function"==typeof r&&(r={cmp:r});var e,n="boolean"==typeof r.cycles&&r.cycles,o=r.cmp&&(e=r.cmp,function(t){return function(r,n){var o={key:r,value:t[r]},c={key:n,value:t[n]};return e(o,c)}}),c=[];return function t(r){if(r&&r.toJSON&&"function"==typeof r.toJSON&&(r=r.toJSON()),void 0!==r){if("number"==typeof r)return isFinite(r)?""+r:"null";if("object"!=typeof r)return JSON.stringify(r);var e,i;if(Array.isArray(r)){for(i="[",e=0;e<r.length;e++)e&&(i+=","),i+=t(r[e])||"null";return i+"]"}if(null===r)return"null";if(-1!==c.indexOf(r)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var u=c.push(r)-1,f=Object.keys(r).sort(o&&o(r));for(i="",e=0;e<f.length;e++){var a=f[e],l=t(r[a]);l&&(i&&(i+=","),i+=JSON.stringify(a)+":"+l)}return c.splice(u,1),"{"+i+"}"}}(t)}));const o=Symbol("__refresh__"),c=(t,r)=>t===r,i=["[object AsyncFunction]","[object AsyncGeneratorFunction]","[object GeneratorFunction]","[object Function]"],u=t=>i.includes(Object.prototype.toString.call(t)),f=t=>!!t&&u(t.then),a=t=>{t[o]()};export{o as R,f as a,c as d,u as i,a as r,n as s};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@rkrupinski/stan",
3
- "description": "Minimalistic state management",
4
- "version": "1.0.0-rc9",
3
+ "description": "Minimal, type-safe state management",
4
+ "version": "1.0.0",
5
+ "main": "./dist/index.js",
5
6
  "exports": {
6
7
  ".": "./dist/index.js",
7
8
  "./react": "./dist/react.js"
@@ -1 +0,0 @@
1
- function r(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var t,e;var n=r(e?t:(e=1,t=function(r,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var e,n="boolean"==typeof t.cycles&&t.cycles,o=t.cmp&&(e=t.cmp,function(r){return function(t,n){var o={key:t,value:r[t]},u={key:n,value:r[n]};return e(o,u)}}),u=[];return function r(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0!==t){if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);var e,i;if(Array.isArray(t)){for(i="[",e=0;e<t.length;e++)e&&(i+=","),i+=r(t[e])||"null";return i+"]"}if(null===t)return"null";if(-1!==u.indexOf(t)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var f=u.push(t)-1,c=Object.keys(t).sort(o&&o(t));for(i="",e=0;e<c.length;e++){var l=c[e],a=r(t[l]);a&&(i&&(i+=","),i+=JSON.stringify(l)+":"+a)}return u.splice(f,1),"{"+i+"}"}}(r)}));const o=Symbol("__refresh__"),u=(r,t)=>r===t,i=r=>{r[o]()};export{o as R,u as d,i as r,n as s};