@rkrupinski/stan 1.1.0 → 1.2.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 +3 -16
- package/dist/atom.d.ts +9 -4
- package/dist/cache.d.ts +6 -19
- package/dist/errors.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/{misc.d.ts → internal.d.ts} +3 -4
- package/dist/react.d.ts +16 -5
- package/dist/react.js +10 -1
- package/dist/react.test.d.ts +4 -0
- package/dist/selector.d.ts +10 -6
- package/dist/state.d.ts +3 -2
- package/dist/store-C_86rrYV.js +1 -0
- package/dist/store.d.ts +8 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils.d.ts +2 -1
- package/package.json +1 -1
- package/dist/utils-D5tiXDeQ.js +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://rkrupinski.github.io/stan)
|
|
2
|
+
|
|
1
3
|
# Stan
|
|
2
4
|
|
|
3
5
|
[](https://github.com/rkrupinski/stan/actions/workflows/ci.yml)
|
|
@@ -7,19 +9,4 @@ Minimal, type-safe state management
|
|
|
7
9
|
|
|
8
10
|
- [Website](https://rkrupinski.github.io/stan)
|
|
9
11
|
- [API docs](https://rkrupinski.github.io/stan/docs/api)
|
|
10
|
-
- [Examples](https://github.
|
|
11
|
-
|
|
12
|
-
```tsx
|
|
13
|
-
import { atom, selector } from '@rkrupinski/stan';
|
|
14
|
-
import { useStanValue } from '@rkrupinski/stan/react';
|
|
15
|
-
|
|
16
|
-
const salary = atom(21);
|
|
17
|
-
const bonus = atom(37);
|
|
18
|
-
const total = selector(({ get }) => get(salary) + get(bonus));
|
|
19
|
-
|
|
20
|
-
const TotalSalary = () => {
|
|
21
|
-
const value = useStanValue(total);
|
|
22
|
-
|
|
23
|
-
return <small>{value}</small>;
|
|
24
|
-
};
|
|
25
|
-
```
|
|
12
|
+
- [Examples](https://rkrupinski.github.io/stan/docs/getting-started/examples)
|
package/dist/atom.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { SetterOrUpdater,
|
|
2
|
-
import { type
|
|
1
|
+
import type { SerializableParam, SetterOrUpdater, TagFromParam } from './types';
|
|
2
|
+
import { type TypedOmit } from './internal';
|
|
3
|
+
import type { WritableState } from './state';
|
|
4
|
+
import type { Scoped } from './store';
|
|
3
5
|
export type AtomEffect<T> = (param: {
|
|
4
6
|
init(value: T): void;
|
|
5
7
|
set: SetterOrUpdater<T>;
|
|
@@ -9,6 +11,9 @@ export type AtomOptions<T> = {
|
|
|
9
11
|
tag?: string;
|
|
10
12
|
effects?: ReadonlyArray<AtomEffect<T>>;
|
|
11
13
|
};
|
|
12
|
-
export declare const atom: <T>(initialValue: T, {
|
|
14
|
+
export declare const atom: <T>(initialValue: T, { tag, effects }?: AtomOptions<T>) => Scoped<WritableState<T>>;
|
|
13
15
|
export type ValueFromParam<T, P extends SerializableParam> = (param: P) => T;
|
|
14
|
-
export
|
|
16
|
+
export type AtomFamilyOptions<T, P extends SerializableParam> = TypedOmit<AtomOptions<T>, 'tag'> & {
|
|
17
|
+
tag?: string | TagFromParam<P>;
|
|
18
|
+
};
|
|
19
|
+
export declare const atomFamily: <T, P extends SerializableParam>(initialValue: T | ValueFromParam<T, P>, { tag, ...other }?: AtomFamilyOptions<T, P>) => (arg: P) => Scoped<WritableState<T>>;
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
export interface Cache<T> {
|
|
2
|
-
has(key: string): boolean;
|
|
3
|
-
get(key: string): T | undefined;
|
|
4
|
-
set(key: string, value: T): void;
|
|
5
|
-
delete(key: string): boolean;
|
|
6
|
-
clear(): void;
|
|
7
|
-
}
|
|
8
|
-
export declare class LRUCache<T> implements Cache<T> {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(maxSize: number);
|
|
11
|
-
has(key: string): boolean;
|
|
12
|
-
get(key: string): T | undefined;
|
|
13
|
-
set(key: string, value: T): void;
|
|
14
|
-
delete(key: string): boolean;
|
|
15
|
-
clear(): void;
|
|
16
|
-
}
|
|
17
|
-
export declare class SimpleCache<T> extends Map<string, T> implements Cache<T> {
|
|
18
|
-
}
|
|
19
1
|
export type CachePolicy = {
|
|
20
2
|
type: 'keep-all';
|
|
21
3
|
} | {
|
|
@@ -24,4 +6,9 @@ export type CachePolicy = {
|
|
|
24
6
|
type: 'lru';
|
|
25
7
|
maxSize: number;
|
|
26
8
|
};
|
|
27
|
-
export
|
|
9
|
+
export type KeyMaker<A> = (arg: A) => any;
|
|
10
|
+
export type MemoizeOptions<A> = {
|
|
11
|
+
cachePolicy?: CachePolicy;
|
|
12
|
+
keyMaker?: KeyMaker<A>;
|
|
13
|
+
};
|
|
14
|
+
export declare const memoize: <A, R>(fn: (arg: A) => R, { cachePolicy, keyMaker, }?: MemoizeOptions<A>) => (arg: A) => R;
|
package/dist/errors.d.ts
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as t,R as s,a,s as c,b as i,c as n,d as l}from"./store-C_86rrYV.js";export{D as DEFAULT_STORE,S as Store,m as makeStore,r as refresh,e as reset}from"./store-C_86rrYV.js";class o extends Error{}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 u extends Map{}const d=(e,{cachePolicy:s={type:"keep-all"},keyMaker:a=t}={})=>{const c=(e=>{switch(e.type){case"keep-all":return new u;case"most-recent":return new h(1);case"lru":return new h(e.maxSize);default:return e}})(s);return t=>{const s=a(t);return c.has(s)||c.set(s,e(t)),c.get(s)}};let g=0;const z=(e,{tag:t,effects:c}={})=>{const i=e,r=`atom${t?`-${t}`:""}-${g++}`;return d((e=>{const n=new Set,l=new Set,o=(t=!1)=>s=>{if(!e.initialized.get(r))return;const c=e.value.get(r),i=a(s)?s(c):s;e.value.set(r,i),n.forEach((e=>e(i))),t||l.forEach((e=>e(i)))},h=o(),u=o(!0);return{tag:t,get:()=>(e.initialized.get(r)||(e.value.set(r,i),c?.forEach((t=>t({init(t){e.initialized.get(r)||e.value.set(r,t)},set:u,onSet(e){l.add(e)}}))),e.initialized.set(r,!0)),e.value.get(r)),set:h,subscribe:e=>(n.add(e),()=>{n.delete(e)}),[s](){h(i)}}}))},f=(e,{tag:t,...s}={})=>d((c=>z(a(e)?e(c):e,{tag:a(t)?t(c):t,...s})),{keyMaker:c});let v=0;const w=(e,{tag:t,areValuesEqual:s=l}={})=>{const a=`selector${t?`-${t}`:""}-${v++}`;return d((c=>{const r=new Set,l=new Set;let h=null,u=0;const d=new Set,g=e=>{const t=e(c);let a=t.get();return r.has(t)||(r.add(t),l.add(t.subscribe((e=>{s(a,e)||(a=e,z(),f())})))),a},z=()=>{const t=++u;l.forEach((e=>e())),l.clear(),r.clear(),h?.abort(new o),h=new AbortController;const s=e({get:g,signal:h.signal});c.value.set(a,s),n(s)&&s.then(void 0,(()=>{t===u&&c.initialized.set(a,!1)}))},f=()=>{d.forEach((e=>e(c.value.get(a))))};return{tag:t,get:()=>(c.initialized.get(a)||(z(),c.initialized.set(a,!0)),c.value.get(a)),subscribe:e=>(0===d.size&&c.mounted.set(a,!0),d.add(e),function(){d.delete(e),0===d.size&&c.mounted.set(a,!1)}),[i](){c.mounted.get(a)?(z(),f()):(c.initialized.set(a,!1),h=null)}}}))},y=(e,{cachePolicy:t,tag:s,...i}={})=>d((t=>w(e(t),{tag:a(s)?s(t):s,...i})),{cachePolicy:t,keyMaker:c});export{o as Aborted,z as atom,f as atomFamily,w as selector,y as selectorFamily};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { default as stableStringify } from 'fast-json-stable-stringify';
|
|
2
|
-
type
|
|
3
|
-
[property: string]: Json;
|
|
4
|
-
} | Json[];
|
|
5
|
-
export type SerializableParam = Json;
|
|
2
|
+
export type TypedOmit<T, K extends keyof T> = Omit<T, K>;
|
|
6
3
|
export declare const REFRESH_TAG: unique symbol;
|
|
4
|
+
export declare const RESET_TAG: unique symbol;
|
|
7
5
|
export declare const dejaVu: <T>(a: T, b: T) => boolean;
|
|
8
6
|
export declare const isFunction: (candidate: any) => candidate is (...args: any[]) => any;
|
|
9
7
|
export declare const isPromiseLike: (candidate: any) => candidate is PromiseLike<any>;
|
|
8
|
+
export declare const identity: <T>(arg: T) => T;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import { type FC, type ReactNode } from 'react';
|
|
1
2
|
import type { State, ReadonlyState, WritableState } from './state';
|
|
3
|
+
import { type Scoped, type Store } from './store';
|
|
4
|
+
export type StanCtxType = {
|
|
5
|
+
store: Store;
|
|
6
|
+
};
|
|
7
|
+
export type StanProviderProps = {
|
|
8
|
+
store?: Store;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare const StanProvider: FC<StanProviderProps>;
|
|
12
|
+
export declare const useStanCtx: () => StanCtxType;
|
|
13
|
+
export declare const useStanValue: <T>(scopedState: Scoped<State<T>>) => T;
|
|
14
|
+
export declare const useSetStanValue: <T>(scopedState: Scoped<WritableState<T>>) => import("./types").SetterOrUpdater<T>;
|
|
15
|
+
export declare const useStan: <T>(scopedState: Scoped<WritableState<T>>) => readonly [T, import("./types").SetterOrUpdater<T>];
|
|
2
16
|
export type AsyncValue<T> = {
|
|
3
17
|
type: 'loading';
|
|
4
18
|
} | {
|
|
@@ -8,8 +22,5 @@ export type AsyncValue<T> = {
|
|
|
8
22
|
type: 'error';
|
|
9
23
|
reason: string;
|
|
10
24
|
};
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const useStanValueAsync: <T>(state: ReadonlyState<PromiseLike<T>>) => AsyncValue<T>;
|
|
14
|
-
export declare const useSetStanValue: <T>(state: WritableState<T>) => import("./state").SetterOrUpdater<T>;
|
|
15
|
-
export declare const useStanRefresher: (state: ReadonlyState<any>) => () => void;
|
|
25
|
+
export declare const useStanValueAsync: <T>(scopedState: Scoped<State<PromiseLike<T>>>) => AsyncValue<T>;
|
|
26
|
+
export declare const useStanRefresher: <T>(scopedState: Scoped<ReadonlyState<T>>) => () => void;
|
package/dist/react.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import e,{createContext as r,useContext as t,useMemo as n,useRef as o,useState as a,useEffect as i,useCallback as s}from"react";import{D as c,m as l,r as u}from"./store-C_86rrYV.js";var f,p={exports:{}},y={};var d,v,m={};
|
|
2
|
+
/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.development.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/function g(){return d||(d=1,"production"!==process.env.NODE_ENV&&function(){var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.provider"),c=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),d=Symbol.for("react.offscreen"),v=Symbol.iterator;var g=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=g.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(r+="%s",t=t.concat([o]));var a=t.map((function(e){return String(e)}));a.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,a)}("error",e,t)}var h;function _(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case i:return"Profiler";case a:return"StrictMode";case u:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return _(e)+".Consumer";case s:return _(e._context)+".Provider";case l:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case p:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case y:var t=e,d=t._payload,v=t._init;try{return k(v(d))}catch(e){return null}}return null}h=Symbol.for("react.module.reference");var w,S,O,j,R,E,P,T=Object.assign,x=0;function $(){}$.__reactDisabledLog=!0;var D,C=g.ReactCurrentDispatcher;function N(e,r,t){if(void 0===D)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);D=n&&n[1]||""}return"\n"+D+e}var F,I=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||I)return"";var t,n=F.get(e);if(void 0!==n)return n;I=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=C.current,C.current=null,function(){if(0===x){w=console.log,S=console.info,O=console.warn,j=console.error,R=console.group,E=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:$,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}x++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var s=r.stack.split("\n"),c=t.stack.split("\n"),l=s.length-1,u=c.length-1;l>=1&&u>=0&&s[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(s[l]!==c[u]){if(1!==l||1!==u)do{if(l--,--u<0||s[l]!==c[u]){var f="\n"+s[l].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&F.set(e,f),f}}while(l>=1&&u>=0);break}}}finally{I=!1,C.current=o,function(){if(0==--x){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:T({},e,{value:w}),info:T({},e,{value:S}),warn:T({},e,{value:O}),error:T({},e,{value:j}),group:T({},e,{value:R}),groupCollapsed:T({},e,{value:E}),groupEnd:T({},e,{value:P})})}x<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",y=p?N(p):"";return"function"==typeof e&&F.set(e,y),y}function W(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case u:return N("Suspense");case f:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case l:return U(e.render,!1);case p:return W(e.type,r,t);case y:var o=e,a=o._payload,i=o._init;try{return W(i(a),r,t)}catch(e){}}return""}F=new L;var A=Object.prototype.hasOwnProperty,z={},M=g.ReactDebugCurrentFrame;function Y(e){if(e){var r=e._owner,t=W(e.type,e._source,r?r.type:null);M.setExtraStackFrame(t)}else M.setExtraStackFrame(null)}var B=Array.isArray;function V(e){return B(e)}function J(e){return""+e}function K(e){if(function(e){try{return J(e),!1}catch(e){return!0}}(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),J(e)}var X,q,H=g.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,n,o,a){var i,s={},c=null,l=null;for(i in void 0!==n&&(K(n),c=""+n),function(e){if(A.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(K(r.key),c=""+r.key),function(e){if(A.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(l=r.ref,function(e){"string"==typeof e.ref&&H.current}(r)),r)A.call(r,i)&&!G.hasOwnProperty(i)&&(s[i]=r[i]);if(e&&e.defaultProps){var u=e.defaultProps;for(i in u)void 0===s[i]&&(s[i]=u[i])}if(c||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){X||(X=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(s,f),l&&function(e,r){var t=function(){q||(q=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(s,f)}return function(e,r,n,o,a,i,s){var c={$$typeof:t,type:e,key:r,ref:n,props:s,_owner:i,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,l,a,o,H.current,s)}var Z,ee=g.ReactCurrentOwner,re=g.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=W(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function ie(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function se(e,r){if("object"==typeof e)if(V(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&ie(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)ne(a.value)&&ie(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==l&&t.$$typeof!==p)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(A);for(var i in e)if(a(e,i)){var s=void 0;try{if("function"!=typeof e[i]){var c=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){s=e}!s||s instanceof Error||(Y(o),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof s),Y(null)),s instanceof Error&&!(s.message in z)&&(z[s.message]=!0,Y(o),b("Failed %s type: %s",t,s.message),Y(null))}}(r,e.props,"prop",n,e)}else if(void 0!==t.PropTypes&&!Z){Z=!0,b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown")}"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function ue(e,r,n,v,m,g){var _=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===i||e===a||e===u||e===f||e===d||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===p||e.$$typeof===s||e.$$typeof===c||e.$$typeof===l||e.$$typeof===h||void 0!==e.getModuleId)}(e);if(!_){var w="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(w+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S;w+=oe(),null===e?S="null":V(e)?S="array":void 0!==e&&e.$$typeof===t?(S="<"+(k(e.type)||"Unknown")+" />",w=" Did you accidentally export a JSX literal instead of a component?"):S=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,w)}var O=Q(e,r,n,m,g);if(null==O)return O;if(_){var j=r.children;if(void 0!==j)if(v)if(V(j)){for(var R=0;R<j.length;R++)se(j[R],e);Object.freeze&&Object.freeze(j)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else se(j,e)}if(A.call(r,"key")){var E=k(e),P=Object.keys(r).filter((function(e){return"key"!==e})),T=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";if(!le[E+T])b('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',T,E,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",E),le[E+T]=!0}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(O):ce(O),O}var fe=function(e,r,t){return ue(e,r,t,!1)},pe=function(e,r,t){return ue(e,r,t,!0)};m.Fragment=o,m.jsx=fe,m.jsxs=pe}()),m}var b=(v||(v=1,"production"===process.env.NODE_ENV?p.exports=function(){if(f)return y;f=1;var r=e,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function s(e,r,n){var s,c={},l=null,u=null;for(s in void 0!==n&&(l=""+n),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(u=r.ref),r)o.call(r,s)&&!i.hasOwnProperty(s)&&(c[s]=r[s]);if(e&&e.defaultProps)for(s in r=e.defaultProps)void 0===c[s]&&(c[s]=r[s]);return{$$typeof:t,type:e,key:l,ref:u,props:c,_owner:a.current}}return y.Fragment=n,y.jsx=s,y.jsxs=s,y}():p.exports=g()),p.exports);const h=r({store:c}),_=({store:e,children:r})=>{const t=n((()=>({store:e??l()})),[e]);return b.jsx(h.Provider,{value:t,children:r})},k=()=>t(h),w=e=>{const{store:r}=k(),t=e(r),n=o(t),[s,c]=a(t.get());return i((()=>(t!==n.current&&(c(t.get()),n.current=t),t.subscribe(c))),[t]),s},S=e=>{const{store:r}=k();return e(r).set},O=e=>[w(e),S(e)],j=e=>{const r=w(e),[t,n]=a({type:"loading"});return i((()=>{let e=!0;return"loading"!==t.type&&n({type:"loading"}),r.then((r=>{e&&n({type:"ready",value:r})}),(r=>{e&&n({type:"error",reason:r?.message??"unknown"})})),()=>{e=!1}}),[r]),t},R=e=>{const{store:r}=k(),t=e(r);return s((()=>{u(t)}),[t])};export{_ as StanProvider,S as useSetStanValue,O as useStan,k as useStanCtx,R as useStanRefresher,w as useStanValue,j as useStanValueAsync};
|
package/dist/selector.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
+
import { type TypedOmit } from './internal';
|
|
1
2
|
import type { ReadonlyState, State } from './state';
|
|
3
|
+
import type { SerializableParam, TagFromParam } from './types';
|
|
4
|
+
import type { Scoped } from './store';
|
|
2
5
|
import { type CachePolicy } from './cache';
|
|
3
|
-
import { type SerializableParam } from './misc';
|
|
4
6
|
export interface GetFn {
|
|
5
|
-
<T>(
|
|
7
|
+
<T>(scopedState: Scoped<State<T>>): T;
|
|
6
8
|
}
|
|
7
|
-
export type SelectorFn<T> = (
|
|
9
|
+
export type SelectorFn<T> = (arg: {
|
|
8
10
|
get: GetFn;
|
|
11
|
+
signal: AbortSignal;
|
|
9
12
|
}) => T;
|
|
10
13
|
export type SelectorOptions = {
|
|
11
14
|
tag?: string;
|
|
12
15
|
areValuesEqual?: <T>(a: T, b: T) => boolean;
|
|
13
16
|
};
|
|
14
|
-
export declare const selector: <T>(selectorFn: SelectorFn<T>, { tag, areValuesEqual }?: SelectorOptions) => ReadonlyState<T
|
|
17
|
+
export declare const selector: <T>(selectorFn: SelectorFn<T>, { tag, areValuesEqual }?: SelectorOptions) => Scoped<ReadonlyState<T>>;
|
|
15
18
|
export type SelectorFamilyFn<T, P extends SerializableParam> = (param: P) => SelectorFn<T>;
|
|
16
|
-
export type SelectorFamilyOptions = SelectorOptions & {
|
|
19
|
+
export type SelectorFamilyOptions<P extends SerializableParam> = TypedOmit<SelectorOptions, 'tag'> & {
|
|
20
|
+
tag?: string | TagFromParam<P>;
|
|
17
21
|
cachePolicy?: CachePolicy;
|
|
18
22
|
};
|
|
19
|
-
export declare const selectorFamily: <T, P extends SerializableParam>(selectorFamilyFn: SelectorFamilyFn<T, P>, {
|
|
23
|
+
export declare const selectorFamily: <T, P extends SerializableParam>(selectorFamilyFn: SelectorFamilyFn<T, P>, { cachePolicy, tag, ...other }?: SelectorFamilyOptions<P>) => (arg: P) => Scoped<ReadonlyState<T>>;
|
package/dist/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SetterOrUpdater } from './types';
|
|
2
|
+
import type { REFRESH_TAG, RESET_TAG } from './internal';
|
|
3
3
|
export interface State<T> {
|
|
4
4
|
tag?: string;
|
|
5
5
|
get(): T;
|
|
@@ -10,4 +10,5 @@ export interface ReadonlyState<T> extends State<T> {
|
|
|
10
10
|
}
|
|
11
11
|
export interface WritableState<T> extends State<T> {
|
|
12
12
|
set: SetterOrUpdater<T>;
|
|
13
|
+
[RESET_TAG](): void;
|
|
13
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,n;var r=e(n?t:(n=1,t=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var n,r="boolean"==typeof t.cycles&&t.cycles,o=t.cmp&&(n=t.cmp,function(e){return function(t,r){var o={key:t,value:e[t]},c={key:r,value:e[r]};return n(o,c)}}),c=[];return function e(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 n,i;if(Array.isArray(t)){for(i="[",n=0;n<t.length;n++)n&&(i+=","),i+=e(t[n])||"null";return i+"]"}if(null===t)return"null";if(-1!==c.indexOf(t)){if(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var a=c.push(t)-1,u=Object.keys(t).sort(o&&o(t));for(i="",n=0;n<u.length;n++){var s=u[n],l=e(t[s]);l&&(i&&(i+=","),i+=JSON.stringify(s)+":"+l)}return c.splice(a,1),"{"+i+"}"}}(e)}));const o=Symbol("__refresh__"),c=Symbol("__reset__"),i=(e,t)=>e===t,a=["[object AsyncFunction]","[object AsyncGeneratorFunction]","[object GeneratorFunction]","[object Function]"],u=e=>a.includes(Object.prototype.toString.call(e)),s=e=>!!e&&u(e.then),l=e=>e,f=e=>{e[o]()},y=e=>{e[c]()};class p{value=new Map;mounted=new Map;initialized=new Map}const _=()=>new p,b=_();export{b as D,c as R,p as S,u as a,o as b,s as c,i as d,y as e,l as i,_ as m,f as r,r as s};
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class Store {
|
|
2
|
+
value: Map<string, any>;
|
|
3
|
+
mounted: Map<string, boolean>;
|
|
4
|
+
initialized: Map<string, boolean>;
|
|
5
|
+
}
|
|
6
|
+
export declare const makeStore: () => Store;
|
|
7
|
+
export declare const DEFAULT_STORE: Store;
|
|
8
|
+
export type Scoped<T> = (store: Store) => T;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Json = string | number | boolean | null | {
|
|
2
|
+
[property: string]: Json;
|
|
3
|
+
} | Json[];
|
|
4
|
+
export type SerializableParam = Json;
|
|
5
|
+
export type TagFromParam<P extends SerializableParam> = (param: P) => string;
|
|
6
|
+
export type SetterOrUpdater<T> = (valueOrUpdater: ((currentValue: T) => T) | T) => void;
|
|
7
|
+
export {};
|
package/dist/utils.d.ts
CHANGED
package/package.json
CHANGED
package/dist/utils-D5tiXDeQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|