@rkrupinski/stan 1.0.0 → 1.1.0-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 +2 -1
- package/dist/atom.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/selector.d.ts +3 -2
- package/dist/state.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Stan
|
|
2
2
|
|
|
3
3
|
[](https://github.com/rkrupinski/stan/actions/workflows/ci.yml)
|
|
4
|
+
[](https://bundlephobia.com/package/@rkrupinski/stan)
|
|
4
5
|
|
|
5
6
|
Minimal, type-safe state management
|
|
6
7
|
|
|
@@ -9,7 +10,7 @@ Minimal, type-safe state management
|
|
|
9
10
|
- [Examples](https://github.com/rkrupinski/stan/tree/master/packages/examples)
|
|
10
11
|
|
|
11
12
|
```tsx
|
|
12
|
-
import { atom } from '@rkrupinski/stan';
|
|
13
|
+
import { atom, selector } from '@rkrupinski/stan';
|
|
13
14
|
import { useStanValue } from '@rkrupinski/stan/react';
|
|
14
15
|
|
|
15
16
|
const salary = atom(21);
|
package/dist/atom.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export type AtomEffect<T> = (param: {
|
|
|
6
6
|
onSet(cb: (value: T) => void): void;
|
|
7
7
|
}) => void;
|
|
8
8
|
export type AtomOptions<T> = {
|
|
9
|
+
tag?: string;
|
|
9
10
|
effects?: ReadonlyArray<AtomEffect<T>>;
|
|
10
11
|
};
|
|
11
|
-
export declare const atom: <T>(initialValue: T, { effects }?: AtomOptions<T>) => WritableState<T>;
|
|
12
|
+
export declare const atom: <T>(initialValue: T, { effects, tag }?: AtomOptions<T>) => WritableState<T>;
|
|
12
13
|
export type ValueFromParam<T, P extends SerializableParam> = (param: P) => T;
|
|
13
14
|
export declare const atomFamily: <T, P extends SerializableParam>(initialValue: T | ValueFromParam<T, P>, options?: AtomOptions<T>) => (param: P) => WritableState<T>;
|
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 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
|
|
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,tag:a}={})=>{let c=!1,r=e;const h=new Set,n=new Set,i=(e=!1)=>s=>{r=t(s)?s(r):s,h.forEach((e=>e(r))),e||n.forEach((e=>e(r)))};return s?.forEach((e=>e({init(e){c||(r=e)},set:i(!0),onSet(e){n.add(e)}}))),c=!0,{tag:a,get:()=>r,set:i(),subscribe:e=>(h.add(e),()=>{h.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,{tag:t,areValuesEqual:r=a}={})=>{let h,n=!1,i=!1;const l=new Set,u=new Set,o=new Set,d=e=>{let t=e.get();if(!u.has(e)){u.add(e);const s=e.subscribe((e=>{r(t,e)||(t=e,f(),g())}));o.add(s)}return t},f=()=>{o.forEach((e=>e())),o.clear(),u.clear(),h=e({get:d}),c(h)&&h.then(void 0,(()=>{n=!1}))},g=()=>{l.forEach((e=>e(h)))};return{tag:t,get:()=>(n||(n=!0,f()),h),subscribe:e=>(0===l.size&&(i=!0),l.add(e),function(){l.delete(e),0===l.size&&(i=!1)}),[s](){i?(f(),g()):n=!1}}},d=(t,{tag:s,areValuesEqual:c=a,cachePolicy:r={type:"keep-all"}}={})=>{const h=i(r);return a=>{const r=e(a);return h.has(r)||h.set(r,o(t(a),{tag:s,areValuesEqual:c})),h.get(r)}};export{l as atom,u as atomFamily,o as selector,d as selectorFamily};
|
package/dist/selector.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ export type SelectorFn<T> = ({ get }: {
|
|
|
8
8
|
get: GetFn;
|
|
9
9
|
}) => T;
|
|
10
10
|
export type SelectorOptions = {
|
|
11
|
+
tag?: string;
|
|
11
12
|
areValuesEqual?: <T>(a: T, b: T) => boolean;
|
|
12
13
|
};
|
|
13
|
-
export declare const selector: <T>(selectorFn: SelectorFn<T>, { areValuesEqual }?: SelectorOptions) => ReadonlyState<T>;
|
|
14
|
+
export declare const selector: <T>(selectorFn: SelectorFn<T>, { tag, areValuesEqual }?: SelectorOptions) => ReadonlyState<T>;
|
|
14
15
|
export type SelectorFamilyFn<T, P extends SerializableParam> = (param: P) => SelectorFn<T>;
|
|
15
16
|
export type SelectorFamilyOptions = SelectorOptions & {
|
|
16
17
|
cachePolicy?: CachePolicy;
|
|
17
18
|
};
|
|
18
|
-
export declare const selectorFamily: <T, P extends SerializableParam>(selectorFamilyFn: SelectorFamilyFn<T, P>, { areValuesEqual, cachePolicy, }?: SelectorFamilyOptions) => (param: P) => ReadonlyState<T>;
|
|
19
|
+
export declare const selectorFamily: <T, P extends SerializableParam>(selectorFamilyFn: SelectorFamilyFn<T, P>, { tag, areValuesEqual, cachePolicy, }?: SelectorFamilyOptions) => (param: P) => ReadonlyState<T>;
|
package/dist/state.d.ts
CHANGED