bansa 0.0.15 → 0.0.16
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.js +6 -6
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var f=class{r;p;a;o;l;get(){if(this.s||(
|
|
1
|
+
var f=class{r;p;a;o;l;get(){if(this.s||(P(this),i(this)),this.state.error)throw this.state.error;if(this.state.promise)throw this.state.promise;return this.state.value}watch(t){return this.s||_(this),(this.o||=new Set).add(t),()=>{this.o.delete(t),this.o.size||i(this)}}subscribe(t){let a={h:t,A:{get signal(){return(a.t||=T()).signal}}};if(!this.s)_(this);else if(!this.state.error&&!this.state.promise)try{t(this.state.value,a.A)}catch(n){p(n)}return(this.l||=new Set).add(a),()=>{this.l.delete(a),a.t&&(a.t.abort(),a.t=void 0),this.l.size||i(this)}}[Symbol.toPrimitive](){return this.state.value}},c=class extends f{n=!1;m=!1;constructor(t,a){super(),this.d=t,this.V=a?.equals,this.r=t,this.state={promise:void 0,error:void 0,value:t}}set(t){let a=t instanceof Function?t(this.r):t;I(a,this.state.value,this.V)||(this.r=a,b(this))}};c.prototype.y=!0;c.prototype.s=!0;c.prototype.u=!1;var y=class extends f{s=!1;u=!1;n=!1;m=!1;f=0;t;i;c;constructor(t,a){super(),this.d=t,this.V=a?.equals,this.b=!!a?.persist;let n=this;this.A={get signal(){return(n.t||=T()).signal}},this.state={promise:k,error:void 0,value:void 0}}};y.prototype.y=!1;var V=()=>V,O=()=>{};Object.setPrototypeOf(V,new Proxy(V,{get:(e,t)=>t===Symbol.toPrimitive?O:V}));var k=Promise.reject();k.catch(O);var m=(e,t)=>e instanceof Function?new y(e,t):new c(e,t),U=e=>m((t,a)=>{let n,r,l=e(s=>{let o=t(s,!1);if(o.error)r=o.error;else if(o.promise)(n||=[]).push(o.promise);else return o.value;return V},a);if(r)throw r;if(n)throw Promise.all(n);return l},{equals:z}),R=(e,t)=>{let a=new WeakMap,n=new WeakMap,r=((l,s=!1)=>{let o=a.get(l);if(!o){let h=e?.(l,!0);if(s)return h;let d=h||l;n.set(l,o=d.d instanceof Function?m((E,K)=>d.d((L,j)=>E(r(L),j),K),{equals:d.V,persist:d.b}):h||m(d.d))}return o});if(t)for(let[l,s]of t)a.set(l,s instanceof f?r(s):m(s));return r},z=(e,t)=>{if(typeof e!="object"||typeof t!="object"||!e||!t)return!1;let a=e.constructor;if(a!==t.constructor)return!1;if(a===Array){let r=e.length;if(r!==t.length)return!1;for(;(r=r-1|0)>=0;)if(!Object.is(e[r],t[r]))return!1;return!0}let n=0;for(let r in e){if(!(r in t&&Object.is(e[r],t[r])))return!1;n=n+1|0}for(let r in t)if((n=n-1|0)<0)return!1;return!0},v=!1,S=[],w=[],_=e=>{e.u||(e.u=!0,b(e))},b=e=>{e.n||(e.n=!0,S.push(e),v||(v=!0,queueMicrotask(C)))},C=()=>{v=!1;{let t=S;S=[];for(let a of t)a.state.promise=void 0,a.state.error=a.p,a.state.value=a.r,D(a)}let e=w;w=[];for(let t=e.length;t--;){let a=e[t];a.m=!1,a.u&&(a.n=!0,P(a)),a.n&&q(a)}},q=e=>{if(e.n=!1,e.o)for(let t of e.o)try{t()}catch(a){p(a)}if(!e.state.error&&!e.state.promise){if(e.l)for(let t of e.l){t.t&&(t.t.abort(),t.t=void 0);try{t.h(e.state.value,t.A)}catch(a){p(a)}}if(e.a)for(let t of e.a)t.u=!0}},D=e=>{if(!e.m){if(e.m=!0,e.a)for(let t of e.a)D(t);w.push(e)}},u=class{e;constructor(t){this.e=t}},G=Symbol(),P=e=>{let t=++e.f;e.s=!0,e.u=!1,e.state.promise=void 0,e.t&&(e.t.abort(),e.t=void 0);try{let a=e.d((n,r=!0)=>{if(t!==e.f)throw G;if(e!==n&&(n.s||(P(n),n.n&&q(n)),(e.c||=new Set).add(n),(n.a||=new Set).add(e)),!r)return n.state;if(n.state.error)throw new u(n.state.error);if(n.state.promise)throw new u(n.state.promise);return n.state.value},e.A);W(a)?(e.state.promise=a,a.then(n=>{t===e.f&&(A(e),I(n,e.state.value,e.V)?e.state.promise=void 0:(e.r=n,e.p=void 0),b(e))},n=>{t===e.f&&(A(e),n instanceof u?n=n.e:p(n),e.p=n,b(e))})):(A(e),e.state.error=void 0,I(a,e.state.value,e.V)?e.n=!1:e.state.value=e.r=a)}catch(a){A(e),a===G?e.n=!1:(a instanceof u?a=a.e:p(a),e.state.error=a)}},A=e=>{++e.f;let t=e.i;if(e.i=e.c,t){for(let a of t)e.i?.has(a)||(a.a.delete(e),i(a));t.clear()}e.c=t},x=!1,g=new Set,i=e=>{!e.y&&!e.b&&!e.a?.size&&!e.o?.size&&!e.l?.size&&(g.add(e),x||(x=!0,setTimeout(M,0)))},M=()=>{for(let e of g)if(!e.y&&!e.b&&!e.a?.size&&!e.o?.size&&!e.l?.size&&(e.state.promise=k,e.r=e.p=e.state.error=e.state.value=void 0,e.n=e.u=e.s=!1,e.t&&(e.t.abort(),e.t=void 0),e.i)){for(let t of e.i)t.a.delete(e),i(t);if(e.i.clear(),e.c){for(let t of e.c)t.a.delete(e),i(t);e.c.clear()}}g.clear(),x=!1},I=(e,t,a)=>Object.is(e,t)||a!==void 0&&t!==void 0&&a(e,t),W=e=>typeof e?.then=="function",T=()=>{let e=new AbortController,t=e.signal,a=new Promise(n=>{t.then=r=>a.then(r),t.addEventListener("abort",n,{once:!0,passive:!0})});return{abort:()=>e.abort(),signal:t}},p=e=>{queueMicrotask(()=>{throw e})};export{m as $,U as $$,R as createScope,k as inactive};
|
package/dist/index.js
CHANGED
|
@@ -146,16 +146,11 @@ const $$ = (init) => $((get, options) => {
|
|
|
146
146
|
const createScope = (parentScope, atomValuePairs) => {
|
|
147
147
|
const scopeMap = /* @__PURE__ */ new WeakMap();
|
|
148
148
|
const atomMap = /* @__PURE__ */ new WeakMap();
|
|
149
|
-
if (atomValuePairs) {
|
|
150
|
-
for (const [atom, value] of atomValuePairs) {
|
|
151
|
-
scopeMap.set(atom, value instanceof CommonAtomInternal ? value : $(value));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
149
|
const scope = ((baseAtom, strict = false) => {
|
|
155
150
|
let scopedAtom = scopeMap.get(baseAtom);
|
|
156
|
-
if (strict) return scopedAtom || parentScope?.(baseAtom, true);
|
|
157
151
|
if (!scopedAtom) {
|
|
158
152
|
const parentAtom = parentScope?.(baseAtom, true);
|
|
153
|
+
if (strict) return parentAtom;
|
|
159
154
|
const realBaseAtom = parentAtom || baseAtom;
|
|
160
155
|
atomMap.set(
|
|
161
156
|
baseAtom,
|
|
@@ -170,6 +165,11 @@ const createScope = (parentScope, atomValuePairs) => {
|
|
|
170
165
|
}
|
|
171
166
|
return scopedAtom;
|
|
172
167
|
});
|
|
168
|
+
if (atomValuePairs) {
|
|
169
|
+
for (const [atom, value] of atomValuePairs) {
|
|
170
|
+
scopeMap.set(atom, value instanceof CommonAtomInternal ? scope(value) : $(value));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
173
|
return scope;
|
|
174
174
|
};
|
|
175
175
|
const shallowEquals = (a, b) => {
|