bansa 0.0.10 → 0.0.11
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.browser.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/react.d.ts +3 -2
- package/dist/react.js +2 -2
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=function(){};p.prototype.get=function(){if(this.o||(
|
|
1
|
+
var p=function(){};p.prototype.get=function(){if(this.o||(I(this),u(this)),this.state.promise)throw this.state.promise;if(this.state.error)throw this.state.error;return this.state.value};p.prototype.watch=function(e){return this.o||g(this),(this.s??=new Set).add(e),()=>{this.s.delete(e),this.s.size||u(this)}};p.prototype.subscribe=function(e){let t={y:e,c:{get signal(){return(t.t??=_()).signal}}};if(!this.o)g(this);else if(!this.state.promise&&!this.state.error)try{e(this.state.value,t.c)}catch(o){y(o)}return(this.u??=new Set).add(t),()=>{this.u.delete(t),t.t&&(t.t.abort(),t.t=void 0),this.u.size||u(this)}};p.prototype[Symbol.toPrimitive]=function(){return this.state.value};var V=function(e,t){this.a=e,this.f=t?.equals,this.state={promise:void 0,error:void 0,value:e},this.state.value=this.l=e};V.prototype.set=function(e){let t=e instanceof Function?e(this.l):e;S(t,this.state.value,this.f)||(this.l=t,d(this))};V.prototype.m=!0;V.prototype.o=!0;V.prototype.n=!1;Object.setPrototypeOf(V.prototype,p.prototype);var c=function(e,t){this.a=e,this.f=t?.equals,this.h=t?.persist,this.state={promise:P,error:void 0,value:void 0};let o=this;this.c={get signal(){return(o.t??=_()).signal}}};c.prototype.m=!1;c.prototype.o=!1;c.prototype.n=!1;c.prototype.i=0;Object.setPrototypeOf(c.prototype,p.prototype);var m=()=>m,O=()=>{};Object.setPrototypeOf(m,new Proxy(m,{get:(e,t)=>t===Symbol.toPrimitive?O:m}));var P=Promise.resolve(),A=(e,t)=>e instanceof Function?new c(e,t):new V(e,t),T=e=>A((t,o)=>{let r,n,f=e((l,h)=>{try{return t(l,h)}catch(a){if(!a)throw a;w(a)?(r??=[]).push(a):n=a}return m},o);if(n)throw n;if(r)throw Promise.all(r);return f},{equals:G}),q=(e,t)=>{let o=new WeakMap;if(t)for(let[r,n]of t)o.set(r,A(n));return(r=>{{let n=o.get(r);if(n)return n}return r.a instanceof Function?A((n,f)=>r.a((l,h)=>{let a=o.get(l);return a||(e?a=e(l):e!==null?a=l:o.set(l,a=A(l.a))),n(a,h)},f)):A(r.a)})},G=(e,t)=>{if(typeof e!="object"||typeof t!="object"||!e||!t)return!1;let o=e.constructor;if(o!==t.constructor)return!1;if(o===Array){let n=e.length;if(n!==t.length)return!1;for(;(n=n-1|0)>=0;)if(!Object.is(e[n],t[n]))return!1;return!0}let r=0;for(let n in e){if(!(n in t&&Object.is(e[n],t[n])))return!1;r=r+1|0}for(let n in t)if((r=r-1|0)<0)return!1;return!0},b=!1,i=[],g=e=>{e.p||(e.p=!0,d(e))},d=e=>{e.n||(e.n=!0,i.push(e),b||(b=!0,queueMicrotask(D)))},D=()=>{b=!1;{let t=i;i=[];for(let o of t)o.state.promise=void 0,o.state.error=o.A,o.state.value=o.l,k(o)}let e=i;i=[];for(let t=e.length;t--;){let o=e[t];o.d=!1,o.p&&(o.n=!0,I(o)),o.n&&x(o)}},x=e=>{if(e.n=!1,e.r)for(let t of e.r)t.p=!0;if(e.s)for(let t of e.s)t();if(e.u&&!e.state.promise&&!e.state.error)for(let t of e.u){t.t&&(t.t.abort(),t.t=void 0);try{t.y(e.state.value,t.c)}catch(o){y(o)}}},k=e=>{if(!e.d){if(e.d=!0,e.r)for(let t of e.r)k(t);i.push(e)}},s=class{e;constructor(t){this.e=t}},I=e=>{let t=++e.i;e.o=!0,e.p=!1,e.state.promise=void 0,e.t&&(e.t.abort(),e.t=void 0);let o=e.V;o&&(e.V=new Set);try{let r=e.a((n,f=!0)=>{if(t!==e.i)throw void 0;if(e!==n&&(n.o||(I(n),n.n&&(n.n=!1,x(n))),o?.delete(n),(e.V??=new Set).add(n),(n.r??=new Set).add(e)),!f)return n.state;if(n.state.promise)throw new s(n.state.promise);if(n.state.error)throw new s(n.state.error);return n.state.value},e.c);w(r)?(e.state.promise=r,r.then(n=>{t===e.i&&(S(n,e.state.value,e.f)?e.state.promise=void 0:(e.l=n,e.A=void 0,d(e)))},n=>{t===e.i&&(n instanceof Promise?e.state.promise=void 0:(n instanceof s?n=n.e:y(n),e.A=n,d(e)))})):(++e.i,e.state.error=void 0,S(r,e.state.value,e.f)?e.n=!1:e.state.value=e.l=r)}catch(r){++e.i,r?(r instanceof s?r=r.e:y(r),w(r)?e.state.promise=r:e.state.error=r):e.n=!1}if(o)for(let r of o)r.r.delete(e),u(r)},v=!1,u=e=>{if(!e.m&&!e.h&&!e.r?.size&&!e.s?.size&&!e.u?.size){if(!v){setTimeout(()=>{v=!0,u(e),v=!1},0);return}if(e.state.promise=P,e.l=e.A=e.state.error=e.state.value=void 0,e.n=e.p=e.o=!1,e.t&&(e.t.abort(),e.t=void 0),e.V){for(let t of e.V)t.r.delete(e),u(t);e.V.clear()}}},S=(e,t,o)=>Object.is(e,t)||o!==void 0&&t!==void 0&&o(e,t),w=e=>typeof e?.then=="function",_=()=>{let e=new AbortController,t=e.signal,o=new Promise(r=>{t.then=n=>o.then(n),t.addEventListener("abort",r,{once:!0,passive:!0})});return{abort:()=>e.abort(),signal:t}},y=e=>{queueMicrotask(()=>{throw e})};export{A as $,T as $$,q as createScope,P as inactive};
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,6 @@ export type MapLike<Key, Value> = Map<Key, Value> | (Key extends object ? WeakMa
|
|
|
77
77
|
export declare const inactive: Promise<void>;
|
|
78
78
|
export declare const $: CreateAtom;
|
|
79
79
|
export declare const $$: <Value>(init: AtomGetter<Value>) => DerivedAtom<Value>;
|
|
80
|
-
type
|
|
81
|
-
export declare const createScope:
|
|
80
|
+
export type AtomValuePair<Value> = [Atom<Value>, Value];
|
|
81
|
+
export declare const createScope: (parentScope?: AtomScope | null, atomValuePairs?: AtomValuePair<unknown>[]) => AtomScope;
|
|
82
82
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -116,9 +116,9 @@ const $ = (init, options) => {
|
|
|
116
116
|
const $$ = (init) => $((get, options) => {
|
|
117
117
|
let promises;
|
|
118
118
|
let error;
|
|
119
|
-
const result = init((atom) => {
|
|
119
|
+
const result = init((atom, unwrap) => {
|
|
120
120
|
try {
|
|
121
|
-
return get(atom);
|
|
121
|
+
return get(atom, unwrap);
|
|
122
122
|
} catch (e) {
|
|
123
123
|
if (!e) {
|
|
124
124
|
throw e;
|
|
@@ -137,10 +137,10 @@ const $$ = (init) => $((get, options) => {
|
|
|
137
137
|
}, {
|
|
138
138
|
equals: shallowEquals
|
|
139
139
|
});
|
|
140
|
-
const createScope = (parentScope,
|
|
140
|
+
const createScope = (parentScope, atomValuePairs) => {
|
|
141
141
|
const scopeMap = /* @__PURE__ */ new WeakMap();
|
|
142
|
-
if (
|
|
143
|
-
for (const [atom, value] of
|
|
142
|
+
if (atomValuePairs) {
|
|
143
|
+
for (const [atom, value] of atomValuePairs) {
|
|
144
144
|
scopeMap.set(atom, $(value));
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -150,14 +150,14 @@ const createScope = (parentScope, atomWithValues) => {
|
|
|
150
150
|
if (scopedAtom) return scopedAtom;
|
|
151
151
|
}
|
|
152
152
|
if (baseAtom.f instanceof Function) return $(
|
|
153
|
-
(get, options) => baseAtom.f((atom) => {
|
|
153
|
+
(get, options) => baseAtom.f((atom, unwrap) => {
|
|
154
154
|
let scopedAtom = scopeMap.get(atom);
|
|
155
155
|
if (!scopedAtom) {
|
|
156
156
|
if (parentScope) scopedAtom = parentScope(atom);
|
|
157
157
|
else if (parentScope !== null) scopedAtom = atom;
|
|
158
158
|
else scopeMap.set(atom, scopedAtom = $(atom.f));
|
|
159
159
|
}
|
|
160
|
-
return get(scopedAtom);
|
|
160
|
+
return get(scopedAtom, unwrap);
|
|
161
161
|
}, options)
|
|
162
162
|
);
|
|
163
163
|
return $(baseAtom.f);
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { $ } from '.';
|
|
2
|
-
import type { Atom, AtomGetter, AtomOptions, AtomScope, DerivedAtom, PrimitiveAtom } from '.';
|
|
2
|
+
import type { Atom, AtomGetter, AtomOptions, AtomScope, AtomValuePair, DerivedAtom, PrimitiveAtom } from '.';
|
|
3
3
|
export declare const ScopeContext: import("react").Context<AtomScope>;
|
|
4
|
-
export declare const ScopeProvider: ({ children }: {
|
|
4
|
+
export declare const ScopeProvider: ({ value, children }: {
|
|
5
|
+
value: AtomValuePair<unknown>[];
|
|
5
6
|
children: React.ReactNode;
|
|
6
7
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export declare const useAtomValue: <Value>(atom: Atom<Value>) => Value;
|
package/dist/react.js
CHANGED
|
@@ -4,9 +4,9 @@ import { $, createScope } from ".";
|
|
|
4
4
|
const ScopeContext = createContext(
|
|
5
5
|
((x) => x)
|
|
6
6
|
);
|
|
7
|
-
const ScopeProvider = ({ children }) => {
|
|
7
|
+
const ScopeProvider = ({ value, children }) => {
|
|
8
8
|
const parentScope = useContext(ScopeContext);
|
|
9
|
-
const scope = useState(() => createScope(parentScope))[0];
|
|
9
|
+
const scope = useState(() => createScope(parentScope, value))[0];
|
|
10
10
|
return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: scope, children });
|
|
11
11
|
};
|
|
12
12
|
const useAtomValue = (atom) => (atom = useContext(ScopeContext)(atom), useSyncExternalStore(
|