Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@benev/slate

Package Overview
Dependencies
Maintainers
0
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@benev/slate - npm Package Compare versions

Comparing version 0.2.15 to 0.2.16

2

package.json
{
"name": "@benev/slate",
"version": "0.2.15",
"version": "0.2.16",
"description": "frontend web stuff",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -13,4 +13,5 @@

export const signal = signals.signal.bind(signals)
export const computed = signals.computed.bind(signals)
export const opSignal = signals.op.bind(signals)
export const reactor = new Reactor(flat, signals)

@@ -8,8 +8,7 @@

await fn()
setTimeout(() => execute(), milliseconds)
setTimeout(execute, milliseconds)
}
}
execute()
setTimeout(execute, milliseconds)
return () => { active = false }

@@ -16,0 +15,0 @@ }

@@ -22,3 +22,3 @@ /**

* SPDX-License-Identifier: BSD-3-Clause
*/};class it extends v{constructor(){super(...arguments),this.renderOptions={host:this},this.o=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this.o=rt(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this.o?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this.o?.setConnected(!1)}render(){return B}}it._$litElement$=!0,it.finalized=!0,globalThis.litElementHydrateSupport?.({LitElement:it});const ot=globalThis.litElementPolyfillSupport;ot?.({LitElement:it}),(globalThis.litElementVersions??=[]).push("4.1.0");class at{#t=!1;lock(t){this.#t=!0;const e=t();return this.#t=!1,e}get locked(){return this.#t}}const ct=()=>new Map,lt=()=>new Set;function ht(t){return{guarantee:(e,s)=>function(t,e,s){if(t.has(e))return t.get(e);{const n=s();return t.set(e,n),n}}(t,e,s)}}class ut{#e=new WeakMap;grab_keymap(t){const e=ht(this.#e).guarantee(t,ct);return{keymap:e,grab_symbolmap:t=>ht(e).guarantee(t,ct)}}clear(){this.#e=new WeakMap}}class dt{#s=new Map;stop(t){const e=this.#s.get(t);e&&(this.#s.delete(t),e())}add(t,e){this.#s.set(t,e)}}class pt{#n=[];record(t){const e=ct();this.#n.push(e);const s=t();return this.#n.pop(),{payload:s,recording:e}}record_that_key_was_accessed(t,e){const s=this.#n.at(-1);if(s){ht(s).guarantee(t,lt).add(e)}}}class ft extends Error{name=this.constructor.name}class gt extends ft{constructor(t){super(`forbidden circularity, rejected assignment to "${t}"`)}}class mt extends ft{constructor(t){super(`forbidden assignment to readonly property "${t}"`)}}function _t(t){return new Proxy(t,{get:(t,e)=>t[e],set(t,e){throw new mt(e)}})}function wt(t,e){let s,n,r=[];function i(){s=[],n&&clearTimeout(n),n=void 0,r=[]}return i(),(...o)=>{s=o,n&&clearTimeout(n);const a=new Promise(((t,e)=>{r.push({resolve:t,reject:e})}));return n=setTimeout((()=>{Promise.resolve().then((()=>e(...s))).then((t=>{for(const{resolve:e}of r)e(t);i()})).catch((t=>{for(const{reject:e}of r)e(t);i()}))}),t),a}}class yt{#r=new Map;#i=Promise.resolve();#o=wt(0,(()=>{const t=[...this.#r.values()];this.#r.clear();for(const e of t)e()}));get wait(){return this.#i}add(t,e){this.#r.set(t,e),this.#i=this.#o()}}function $t(t){return function(e){return()=>{const s="function"==typeof t?t():t;return e(s)}}}function bt(t,e,s,n){const r=[];for(const[i,o]of e){const{grab_symbolmap:e}=s.grab_keymap(i);for(const s of o){const i=e(s);i.set(t,n),r.push((()=>i.delete(t)))}}return()=>r.forEach((t=>t()))}class vt{#a;constructor(t){this.#a=t}get state(){return this.#a.getter(this.#a.parent.state)}transmute(t){this.#a.parent.transmute((e=>{const s=this.#a.getter(e),n=t(s);return this.#a.setter(e,n)}))}slice({getter:t,setter:e}){return new vt({parent:this,getter:t,setter:e})}}const At=t=>"object"==typeof t&&null!==t;const St={clone:function t(e,s=new Set){if(s.has(e))throw new Error("cannot clone circular reference");let n;return"function"==typeof e||null!==e&&"object"==typeof e?(s.add(e),n=Array.isArray(e)?e.map((e=>t(e,new Set(s)))):e.constructor===Object?Object.fromEntries(Object.entries(e).map((([e,n])=>[e,t(n,new Set(s))]))):e instanceof Map?new Map(Array.from(e,(([e,n])=>[e,t(n,new Set(s))]))):e instanceof Set?new Set(Array.from(e,(e=>t(e,new Set(s))))):e instanceof Date?new Date(e.getTime()):e,s.delete(e)):n=e,n},equal:(t,e)=>function t(e,s,n){if(!At(e)||!At(s))return e===s;if(n.includes(e))throw new Error("forbidden circularity detected in deep equal comparison");const r=[...n,e];if(e instanceof Map&&s instanceof Map){if(e.size!==s.size)return!1;for(const[n,i]of e)if(!s.has(n)||!t(i,s.get(n),r))return!1}else if(e instanceof Set&&s instanceof Set){if(e.size!==s.size)return!1;for(const n of e)if(!Array.from(s).some((e=>t(n,e,r))))return!1}else{const n=Object.keys(e),i=Object.keys(s);if(n.length!==i.length)return!1;for(const o of n){if(!i.includes(o))return!1;if(!t(e[o],s[o],r))return!1}}return!0}(t,e,[]),freeze:function(t){return function t(e,s){if(!At(e)||s.includes(e))return e;const n=[...s,e];if(e instanceof Map)for(const s of e.entries())for(const e of s)t(e,n);else if(e instanceof Set)for(const s of e)t(s,n);else if(Array.isArray(e))for(const s of e)t(s,n);else for(const s of Object.values(e))t(s,n);return Object.freeze(e)}(t,[])}};class kt{#c;#l;#h;#u=!1;#d(){return St.freeze(structuredClone(this.#c))}constructor(t,e=()=>{}){this.#c=structuredClone(t),this.#l=this.#d(),this.#h=e}get state(){return this.#l}transmute(t){if(this.#u)throw new Error("circular error");this.#u=!0,this.#c=t(structuredClone(this.#c)),this.#l=this.#d(),this.#h(),this.#u=!1}slice({getter:t,setter:e}){return new vt({parent:this,getter:t,setter:e})}}const xt=Error;var Ct;function Et(t){return{map:e=>Mt(t,e),filter:e=>Pt(t,e)}}!function(t){function e(t){return"ready"===t.status?t.payload:void 0}function s(t,e){switch(t.status){case"loading":return e.loading();case"error":return e.error(t.reason);case"ready":return e.ready(t.payload);default:throw console.error("op",t),new xt("invalid op status")}}t.loading=()=>({status:"loading"}),t.error=t=>({status:"error",reason:t}),t.ready=t=>({status:"ready",payload:t}),t.is=Object.freeze({loading:t=>"loading"===t.status,error:t=>"error"===t.status,ready:t=>"ready"===t.status}),t.payload=e,t.reason=function(t){return"error"===t.status?t.reason:void 0},t.select=s,t.load=async function(e,s){e(t.loading());try{const n=await s();return e(t.ready(n)),n}catch(s){const n=s instanceof xt?s.message:"string"==typeof s?s:"error";throw e(t.error(n)),s}},t.morph=function(e,n){return s(e,{loading:()=>t.loading(),error:e=>t.error(e),ready:e=>t.ready(n(e))})},t.all=function(...s){const n=s.find(t.is.error);return n||(s.every(t.is.ready)?t.ready(s.map(e)):t.loading())}}(Ct||(Ct={})),Et.pipe=Object.freeze({map:t=>e=>Mt(e,t),filter:t=>e=>Pt(e,t)});const Mt=(t,e)=>Object.fromEntries(Object.entries(t).map((([t,s])=>[t,e(s,t)]))),Pt=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t,s])=>e(s,t)))),Ut=Symbol();class Ot extends Error{name=this.constructor.name}class Tt{static unwrap=t=>t instanceof Tt?t.value:t;#p;#f=!1;#i;#g=new Set;[Ut]=!1;constructor(t){this.#p=t,this.#i=Promise.resolve(t)}subscribe(t){return this.on(t)}on(t){return this.#g.add(t),()=>{this.#g.delete(t)}}once(t){const e=s=>{t(s),this.#g.delete(e)};return this.#g.add(e),()=>{this.#g.delete(e)}}clear(){return this.#g.clear()}#m=wt(0,(()=>{const t=this.#p;this.#f=!0;for(const e of this.#g)e(t);return this.#f=!1,t}));async publish(){this.#i=this.#m(),await this.#i}get wait(){return this.#i}get value(){return this[Ut]=!0,this.#p}set value(t){if(this.#f)throw new Ot("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");this.#p=t,this.publish()}setValueNoPublish(t){this.#p=t}}class Rt extends Tt{constructor(t){super(t)}async load(t){return Ct.load((t=>this.value=t),t)}setLoading(){this.value=Ct.loading()}setError(t){this.value=Ct.error(t)}setReady(t){this.value=Ct.ready(t)}isLoading(){return Ct.is.loading(this.value)}isError(){return Ct.is.error(this.value)}isReady(){return Ct.is.ready(this.value)}get payload(){return Ct.payload(this.value)}select(t){return Ct.select(this.value,t)}}class Nt{#_=!0;#w;#y;#$=new Set;#b=new Set;constructor({all_signals:t,waiters:e}){this.#w=t,this.#y=e}#o=wt(0,(t=>{if(this.#_)if("lean"in t)t.actor();else{const{payload:e,recording:s}=this.observe(t.collector);this.add_listeners(t,s),t.responder&&t.responder(e)}}));#v(){for(const t of this.#w)t[Ut]=!1}get#A(){return[...this.#w].filter((t=>t[Ut]&&!this.#$.has(t)))}observe(t){this.#v();return{payload:t(),recording:this.#A}}add_listeners(t,e){for(const s of e)this.#$.add(s),this.#b.add(s.subscribe((()=>this.#y.add(this.#o(t)))))}shutdown(){this.#_=!1,this.#b.forEach((t=>t()))}}const Ht=new class{static readonly=_t;static collectivize=$t;#S=new ut;#k=new pt;#x=new at;#C=new dt;#E=new yt;#M=function(t,e,s,n,r){function i([s,r]){if("lean"in r)r.actor();else{const{payload:i,recording:o}=e.record(r.collector);n.add(s,bt(s,o,t,r)),r.responder&&r.responder(i)}}return{get:(t,s)=>(e.record_that_key_was_accessed(t,s),t[s]),set:(e,n,o)=>{if(s.locked)throw new gt(n);e[n]=o;const a=[...t.grab_keymap(e).grab_symbolmap(n)];for(const t of a){const[e]=t;r.add(e,(()=>s.lock((()=>i(t)))))}return!0}}}(this.#S,this.#k,this.#x,this.#C,this.#E);get wait(){return this.#E.wait}state(t){return new Proxy(t,this.#M)}reaction(t,e){const s=Symbol(),{recording:n}=this.#k.record((()=>this.#x.lock(t)));return this.#C.add(s,bt(s,n,this.#S,{collector:t,responder:e})),()=>this.#C.stop(s)}lean(t){const e=Symbol();return{stop:()=>this.#C.stop(e),collect:s=>{const{payload:n,recording:r}=this.#k.record((()=>this.#x.lock(s)));return this.#C.add(e,bt(e,r,this.#S,{lean:!0,actor:t})),n}}}clear(){this.#S.clear()}},jt=new class{#P=new Set;#y=new Set;signal(t){const e=new Tt(t);return this.#P.add(e),e}computed(t){const e=this.signal(t());return this.reaction((()=>{e.value=t()})),e}async computedAsync(t,e){const s=await e(t()),n=this.signal(s);return this.reaction(t,(async t=>{n.value=await e(t)})),n}op(t=Ct.loading()){const e=new Rt(t);return this.#P.add(e),e}many(t){return Et(t).map((t=>this.signal(t)))}reaction(t,e){const s=new Nt({waiters:this.#y,all_signals:this.#P}),n={collector:t,responder:e},{recording:r}=s.observe(n.collector);return s.add_listeners(n,r),()=>s.shutdown()}lean(t){const e=new Nt({waiters:this.#y,all_signals:this.#P}),s={lean:!0,actor:t};return{stop:()=>e.shutdown(),collect:t=>{const{payload:n,recording:r}=e.observe(t);return e.add_listeners(s,r),n}}}get wait(){return Promise.all([...this.#P].map((t=>t.wait))).then((()=>Promise.all([...this.#y]))).then((()=>{this.#y.clear()}))}},zt=new class{#P;#U=new Set;#g=new Set;#O=new Map;#T=Promise.resolve();constructor(t){this.#P=t}get wait(){return this.#T}#R=wt(0,(()=>{for(const t of this.#U)t();for(const t of this.#g)t()}));dispatch(){this.#T=this.#R()}computed(t){const e=this.#P.signal(t());return this.#U.add((()=>{e.value=t()})),e}track(t,e){let s=!0;const n=()=>{const n=t(),r=this.#O.get(t);!s&&St.equal(n,r)||(s=!1,this.#O.set(t,n),e(n))};n(),this.#g.add(n);return()=>this.#g.delete(n)}stateTree(t){return new kt(t,(()=>this.dispatch()))}}(jt);Ht.state.bind(Ht),jt.signal.bind(jt),jt.op.bind(jt);const qt=new class{flat;signals;#i=Promise.resolve();constructor(t,e){this.flat=t,this.signals=e}get wait(){return Promise.all([this.flat.wait,this.signals.wait]).then((()=>this.#i))}reaction(t,e){const s=e?()=>e(r()):()=>r(),n=this.lean(s),r=()=>n.collect(t);return r(),n.stop}lean(t){const e=this.flat.lean(t),s=this.signals.lean(t);return{stop(){e.stop(),s.stop()},collect:t=>e.collect((()=>s.collect(t)))}}}(Ht,jt);class Dt extends(function(t){return class extends t{#N=(new Set).add((()=>this.setup()));#H=new Set;register_setup(t){this.#N.add(t)}setup(){return()=>{}}connectedCallback(){for(const t of this.#N)this.#H.add(t())}disconnectedCallback(){for(const t of this.#H)t();this.#H.clear()}}}(HTMLElement)){}function Vt(){let t,e;const s=new Promise(((s,n)=>{t=s,e=n}));return{promise:s,resolve:t,reject:e,entangle:function(n){return n.then(t).catch(e),s}}}function Lt(t,e){o(t,function(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}(e))}class Bt extends Dt{static get styles(){}#j;#z=Vt();#i=this.#z.promise;init(){}constructor(){super(),this.#j=this.attachShadow({mode:"open"});const t=this.constructor;Lt(this.#j,t.styles),this.init()}get root(){return this.#j}get updateComplete(){return this.#i.then((()=>!0))}render(){}#q=wt(0,(()=>{const t=this.#j,e=this.render();e&&rt(e,t,{host:this})}));async requestUpdate(){const t=this.#q();return this.#z&&(t.then(this.#z.resolve),this.#z=void 0),this.#i=t,t}connectedCallback(){super.connectedCallback(),this.requestUpdate()}}const It=i`
*/};class it extends v{constructor(){super(...arguments),this.renderOptions={host:this},this.o=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this.o=rt(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this.o?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this.o?.setConnected(!1)}render(){return B}}it._$litElement$=!0,it.finalized=!0,globalThis.litElementHydrateSupport?.({LitElement:it});const ot=globalThis.litElementPolyfillSupport;ot?.({LitElement:it}),(globalThis.litElementVersions??=[]).push("4.1.0");class at{#t=!1;lock(t){this.#t=!0;const e=t();return this.#t=!1,e}get locked(){return this.#t}}const ct=()=>new Map,lt=()=>new Set;function ht(t){return{guarantee:(e,s)=>function(t,e,s){if(t.has(e))return t.get(e);{const n=s();return t.set(e,n),n}}(t,e,s)}}class ut{#e=new WeakMap;grab_keymap(t){const e=ht(this.#e).guarantee(t,ct);return{keymap:e,grab_symbolmap:t=>ht(e).guarantee(t,ct)}}clear(){this.#e=new WeakMap}}class dt{#s=new Map;stop(t){const e=this.#s.get(t);e&&(this.#s.delete(t),e())}add(t,e){this.#s.set(t,e)}}class pt{#n=[];record(t){const e=ct();this.#n.push(e);const s=t();return this.#n.pop(),{payload:s,recording:e}}record_that_key_was_accessed(t,e){const s=this.#n.at(-1);if(s){ht(s).guarantee(t,lt).add(e)}}}class ft extends Error{name=this.constructor.name}class gt extends ft{constructor(t){super(`forbidden circularity, rejected assignment to "${t}"`)}}class mt extends ft{constructor(t){super(`forbidden assignment to readonly property "${t}"`)}}function _t(t){return new Proxy(t,{get:(t,e)=>t[e],set(t,e){throw new mt(e)}})}function wt(t,e){let s,n,r=[];function i(){s=[],n&&clearTimeout(n),n=void 0,r=[]}return i(),(...o)=>{s=o,n&&clearTimeout(n);const a=new Promise(((t,e)=>{r.push({resolve:t,reject:e})}));return n=setTimeout((()=>{Promise.resolve().then((()=>e(...s))).then((t=>{for(const{resolve:e}of r)e(t);i()})).catch((t=>{for(const{reject:e}of r)e(t);i()}))}),t),a}}class yt{#r=new Map;#i=Promise.resolve();#o=wt(0,(()=>{const t=[...this.#r.values()];this.#r.clear();for(const e of t)e()}));get wait(){return this.#i}add(t,e){this.#r.set(t,e),this.#i=this.#o()}}function $t(t){return function(e){return()=>{const s="function"==typeof t?t():t;return e(s)}}}function bt(t,e,s,n){const r=[];for(const[i,o]of e){const{grab_symbolmap:e}=s.grab_keymap(i);for(const s of o){const i=e(s);i.set(t,n),r.push((()=>i.delete(t)))}}return()=>r.forEach((t=>t()))}class vt{#a;constructor(t){this.#a=t}get state(){return this.#a.getter(this.#a.parent.state)}transmute(t){this.#a.parent.transmute((e=>{const s=this.#a.getter(e),n=t(s);return this.#a.setter(e,n)}))}slice({getter:t,setter:e}){return new vt({parent:this,getter:t,setter:e})}}const At=t=>"object"==typeof t&&null!==t;const St={clone:function t(e,s=new Set){if(s.has(e))throw new Error("cannot clone circular reference");let n;return"function"==typeof e||null!==e&&"object"==typeof e?(s.add(e),n=Array.isArray(e)?e.map((e=>t(e,new Set(s)))):e.constructor===Object?Object.fromEntries(Object.entries(e).map((([e,n])=>[e,t(n,new Set(s))]))):e instanceof Map?new Map(Array.from(e,(([e,n])=>[e,t(n,new Set(s))]))):e instanceof Set?new Set(Array.from(e,(e=>t(e,new Set(s))))):e instanceof Date?new Date(e.getTime()):e,s.delete(e)):n=e,n},equal:(t,e)=>function t(e,s,n){if(!At(e)||!At(s))return e===s;if(n.includes(e))throw new Error("forbidden circularity detected in deep equal comparison");const r=[...n,e];if(e instanceof Map&&s instanceof Map){if(e.size!==s.size)return!1;for(const[n,i]of e)if(!s.has(n)||!t(i,s.get(n),r))return!1}else if(e instanceof Set&&s instanceof Set){if(e.size!==s.size)return!1;for(const n of e)if(!Array.from(s).some((e=>t(n,e,r))))return!1}else{const n=Object.keys(e),i=Object.keys(s);if(n.length!==i.length)return!1;for(const o of n){if(!i.includes(o))return!1;if(!t(e[o],s[o],r))return!1}}return!0}(t,e,[]),freeze:function(t){return function t(e,s){if(!At(e)||s.includes(e))return e;const n=[...s,e];if(e instanceof Map)for(const s of e.entries())for(const e of s)t(e,n);else if(e instanceof Set)for(const s of e)t(s,n);else if(Array.isArray(e))for(const s of e)t(s,n);else for(const s of Object.values(e))t(s,n);return Object.freeze(e)}(t,[])}};class kt{#c;#l;#h;#u=!1;#d(){return St.freeze(structuredClone(this.#c))}constructor(t,e=()=>{}){this.#c=structuredClone(t),this.#l=this.#d(),this.#h=e}get state(){return this.#l}transmute(t){if(this.#u)throw new Error("circular error");this.#u=!0,this.#c=t(structuredClone(this.#c)),this.#l=this.#d(),this.#h(),this.#u=!1}slice({getter:t,setter:e}){return new vt({parent:this,getter:t,setter:e})}}const xt=Error;var Ct;function Et(t){return{map:e=>Mt(t,e),filter:e=>Pt(t,e)}}!function(t){function e(t){return"ready"===t.status?t.payload:void 0}function s(t,e){switch(t.status){case"loading":return e.loading();case"error":return e.error(t.reason);case"ready":return e.ready(t.payload);default:throw console.error("op",t),new xt("invalid op status")}}t.loading=()=>({status:"loading"}),t.error=t=>({status:"error",reason:t}),t.ready=t=>({status:"ready",payload:t}),t.is=Object.freeze({loading:t=>"loading"===t.status,error:t=>"error"===t.status,ready:t=>"ready"===t.status}),t.payload=e,t.reason=function(t){return"error"===t.status?t.reason:void 0},t.select=s,t.load=async function(e,s){e(t.loading());try{const n=await s();return e(t.ready(n)),n}catch(s){const n=s instanceof xt?s.message:"string"==typeof s?s:"error";throw e(t.error(n)),s}},t.morph=function(e,n){return s(e,{loading:()=>t.loading(),error:e=>t.error(e),ready:e=>t.ready(n(e))})},t.all=function(...s){const n=s.find(t.is.error);return n||(s.every(t.is.ready)?t.ready(s.map(e)):t.loading())}}(Ct||(Ct={})),Et.pipe=Object.freeze({map:t=>e=>Mt(e,t),filter:t=>e=>Pt(e,t)});const Mt=(t,e)=>Object.fromEntries(Object.entries(t).map((([t,s])=>[t,e(s,t)]))),Pt=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t,s])=>e(s,t)))),Ut=Symbol();class Ot extends Error{name=this.constructor.name}class Tt{static unwrap=t=>t instanceof Tt?t.value:t;#p;#f=!1;#i;#g=new Set;[Ut]=!1;constructor(t){this.#p=t,this.#i=Promise.resolve(t)}subscribe(t){return this.on(t)}on(t){return this.#g.add(t),()=>{this.#g.delete(t)}}once(t){const e=s=>{t(s),this.#g.delete(e)};return this.#g.add(e),()=>{this.#g.delete(e)}}clear(){return this.#g.clear()}#m=wt(0,(()=>{const t=this.#p;this.#f=!0;for(const e of this.#g)e(t);return this.#f=!1,t}));async publish(){this.#i=this.#m(),await this.#i}get wait(){return this.#i}get value(){return this[Ut]=!0,this.#p}set value(t){if(this.#f)throw new Ot("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");this.#p=t,this.publish()}setValueNoPublish(t){this.#p=t}}class Rt extends Tt{constructor(t){super(t)}async load(t){return Ct.load((t=>this.value=t),t)}setLoading(){this.value=Ct.loading()}setError(t){this.value=Ct.error(t)}setReady(t){this.value=Ct.ready(t)}isLoading(){return Ct.is.loading(this.value)}isError(){return Ct.is.error(this.value)}isReady(){return Ct.is.ready(this.value)}get payload(){return Ct.payload(this.value)}select(t){return Ct.select(this.value,t)}}class Nt{#_=!0;#w;#y;#$=new Set;#b=new Set;constructor({all_signals:t,waiters:e}){this.#w=t,this.#y=e}#o=wt(0,(t=>{if(this.#_)if("lean"in t)t.actor();else{const{payload:e,recording:s}=this.observe(t.collector);this.add_listeners(t,s),t.responder&&t.responder(e)}}));#v(){for(const t of this.#w)t[Ut]=!1}get#A(){return[...this.#w].filter((t=>t[Ut]&&!this.#$.has(t)))}observe(t){this.#v();return{payload:t(),recording:this.#A}}add_listeners(t,e){for(const s of e)this.#$.add(s),this.#b.add(s.subscribe((()=>this.#y.add(this.#o(t)))))}shutdown(){this.#_=!1,this.#b.forEach((t=>t()))}}const Ht=new class{static readonly=_t;static collectivize=$t;#S=new ut;#k=new pt;#x=new at;#C=new dt;#E=new yt;#M=function(t,e,s,n,r){function i([s,r]){if("lean"in r)r.actor();else{const{payload:i,recording:o}=e.record(r.collector);n.add(s,bt(s,o,t,r)),r.responder&&r.responder(i)}}return{get:(t,s)=>(e.record_that_key_was_accessed(t,s),t[s]),set:(e,n,o)=>{if(s.locked)throw new gt(n);e[n]=o;const a=[...t.grab_keymap(e).grab_symbolmap(n)];for(const t of a){const[e]=t;r.add(e,(()=>s.lock((()=>i(t)))))}return!0}}}(this.#S,this.#k,this.#x,this.#C,this.#E);get wait(){return this.#E.wait}state(t){return new Proxy(t,this.#M)}reaction(t,e){const s=Symbol(),{recording:n}=this.#k.record((()=>this.#x.lock(t)));return this.#C.add(s,bt(s,n,this.#S,{collector:t,responder:e})),()=>this.#C.stop(s)}lean(t){const e=Symbol();return{stop:()=>this.#C.stop(e),collect:s=>{const{payload:n,recording:r}=this.#k.record((()=>this.#x.lock(s)));return this.#C.add(e,bt(e,r,this.#S,{lean:!0,actor:t})),n}}}clear(){this.#S.clear()}},jt=new class{#P=new Set;#y=new Set;signal(t){const e=new Tt(t);return this.#P.add(e),e}computed(t){const e=this.signal(t());return this.reaction((()=>{e.value=t()})),e}async computedAsync(t,e){const s=await e(t()),n=this.signal(s);return this.reaction(t,(async t=>{n.value=await e(t)})),n}op(t=Ct.loading()){const e=new Rt(t);return this.#P.add(e),e}many(t){return Et(t).map((t=>this.signal(t)))}reaction(t,e){const s=new Nt({waiters:this.#y,all_signals:this.#P}),n={collector:t,responder:e},{recording:r}=s.observe(n.collector);return s.add_listeners(n,r),()=>s.shutdown()}lean(t){const e=new Nt({waiters:this.#y,all_signals:this.#P}),s={lean:!0,actor:t};return{stop:()=>e.shutdown(),collect:t=>{const{payload:n,recording:r}=e.observe(t);return e.add_listeners(s,r),n}}}get wait(){return Promise.all([...this.#P].map((t=>t.wait))).then((()=>Promise.all([...this.#y]))).then((()=>{this.#y.clear()}))}},zt=new class{#P;#U=new Set;#g=new Set;#O=new Map;#T=Promise.resolve();constructor(t){this.#P=t}get wait(){return this.#T}#R=wt(0,(()=>{for(const t of this.#U)t();for(const t of this.#g)t()}));dispatch(){this.#T=this.#R()}computed(t){const e=this.#P.signal(t());return this.#U.add((()=>{e.value=t()})),e}track(t,e){let s=!0;const n=()=>{const n=t(),r=this.#O.get(t);!s&&St.equal(n,r)||(s=!1,this.#O.set(t,n),e(n))};n(),this.#g.add(n);return()=>this.#g.delete(n)}stateTree(t){return new kt(t,(()=>this.dispatch()))}}(jt);Ht.state.bind(Ht),jt.signal.bind(jt),jt.computed.bind(jt),jt.op.bind(jt);const qt=new class{flat;signals;#i=Promise.resolve();constructor(t,e){this.flat=t,this.signals=e}get wait(){return Promise.all([this.flat.wait,this.signals.wait]).then((()=>this.#i))}reaction(t,e){const s=e?()=>e(r()):()=>r(),n=this.lean(s),r=()=>n.collect(t);return r(),n.stop}lean(t){const e=this.flat.lean(t),s=this.signals.lean(t);return{stop(){e.stop(),s.stop()},collect:t=>e.collect((()=>s.collect(t)))}}}(Ht,jt);class Dt extends(function(t){return class extends t{#N=(new Set).add((()=>this.setup()));#H=new Set;register_setup(t){this.#N.add(t)}setup(){return()=>{}}connectedCallback(){for(const t of this.#N)this.#H.add(t())}disconnectedCallback(){for(const t of this.#H)t();this.#H.clear()}}}(HTMLElement)){}function Vt(){let t,e;const s=new Promise(((s,n)=>{t=s,e=n}));return{promise:s,resolve:t,reject:e,entangle:function(n){return n.then(t).catch(e),s}}}function Lt(t,e){o(t,function(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}(e))}class Bt extends Dt{static get styles(){}#j;#z=Vt();#i=this.#z.promise;init(){}constructor(){super(),this.#j=this.attachShadow({mode:"open"});const t=this.constructor;Lt(this.#j,t.styles),this.init()}get root(){return this.#j}get updateComplete(){return this.#i.then((()=>!0))}render(){}#q=wt(0,(()=>{const t=this.#j,e=this.render();e&&rt(e,t,{host:this})}));async requestUpdate(){const t=this.#q();return this.#z&&(t.then(this.#z.resolve),this.#z=void 0),this.#i=t,t}connectedCallback(){super.connectedCallback(),this.requestUpdate()}}const It=i`
* {

@@ -25,0 +25,0 @@ margin: 0;

@@ -10,3 +10,4 @@ import { Flat } from "../flatstate/flat.js";

export declare const signal: <V>(value: V) => import("../index.js").Signal<V>;
export declare const computed: <V>(fun: () => V) => import("../index.js").Signal<V>;
export declare const opSignal: <V>(op?: import("../index.js").Op.For<V>) => import("../index.js").OpSignal<V>;
export declare const reactor: Reactor;

@@ -10,4 +10,5 @@ import { Flat } from "../flatstate/flat.js";

export const signal = signals.signal.bind(signals);
export const computed = signals.computed.bind(signals);
export const opSignal = signals.op.bind(signals);
export const reactor = new Reactor(flat, signals);
//# sourceMappingURL=state.js.map

@@ -6,6 +6,6 @@ export function repeat(milliseconds, fn) {

await fn();
setTimeout(() => execute(), milliseconds);
setTimeout(execute, milliseconds);
}
};
execute();
setTimeout(execute, milliseconds);
return () => { active = false; };

@@ -12,0 +12,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc