sinho 0.1.4 → 0.2.0
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/bundle.d.ts +2 -1
- package/dist/bundle.js +41 -27
- package/dist/bundle.min.js +1 -1
- package/dist/dom.js +1 -7
- package/dist/dom.js.map +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +1 -1
- package/dist/scope.d.ts +1 -0
- package/dist/scope.js +39 -20
- package/dist/scope.js.map +1 -1
- package/package.json +1 -1
- package/src/dom.ts +1 -5
- package/src/mod.ts +3 -2
- package/src/scope.ts +47 -21
- package/dist/intrinsic/Dynamic.d.ts +0 -33
- package/dist/intrinsic/Dynamic.js +0 -53
- package/dist/intrinsic/Dynamic.js.map +0 -1
- package/dist/intrinsic/ErrorBoundary.d.ts +0 -14
- package/dist/intrinsic/ErrorBoundary.js +0 -36
- package/dist/intrinsic/ErrorBoundary.js.map +0 -1
- package/web/dist/shingo.min.d.ts +0 -1131
- package/web/dist/shingo.min.js +0 -1
- package/web/static/dist/bundle.d.ts +0 -1126
- package/web/static/dist/bundle.min.js +0 -1
package/dist/bundle.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ declare const useSignal: (<T>(value: T, opts?: SetSignalOptions) => readonly [Si
|
|
|
71
71
|
* and updated at the same time.
|
|
72
72
|
*/
|
|
73
73
|
declare const useBatch: <T>(fn: () => T) => T;
|
|
74
|
+
declare function flushBatch(): void;
|
|
74
75
|
/**
|
|
75
76
|
* Creates a memoized signal.
|
|
76
77
|
*
|
|
@@ -1130,4 +1131,4 @@ declare namespace JSX {
|
|
|
1130
1131
|
}
|
|
1131
1132
|
}
|
|
1132
1133
|
|
|
1133
|
-
export { type AttributeOptions, type Children, type Cleanup, Component, type ComponentConstructor, type ComponentOptions, type Context, type DangerousHtml, Else, ElseIf, type EventConstructor, For, Fragment, type FunctionalComponent, If, JSX, MaybeSignal, type Metadata, Portal, type PropOptions, type RefSignal, type RefSignalSetter, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, Style, type Styles, type SubscopeOptions, type Template, createContext, createElement, css, defineComponents, event, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
|
1134
|
+
export { type AttributeOptions, type Children, type Cleanup, Component, type ComponentConstructor, type ComponentOptions, type Context, type DangerousHtml, Else, ElseIf, type EventConstructor, For, Fragment, type FunctionalComponent, If, JSX, MaybeSignal, type Metadata, Portal, type PropOptions, type RefSignal, type RefSignalSetter, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, Style, type Styles, type SubscopeOptions, type Template, createContext, createElement, css, defineComponents, event, flushBatch, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
package/dist/bundle.js
CHANGED
|
@@ -62,7 +62,10 @@ const useSignal = (value, opts) => {
|
|
|
62
62
|
value = newValue;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
currBatch._setters.push(() =>
|
|
65
|
+
currBatch._setters.push(() => {
|
|
66
|
+
value = newValue;
|
|
67
|
+
return signal;
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
if (!innerOpts?.silent) {
|
|
68
71
|
signal._effects.forEach((effect) => currBatch._effects.add(effect));
|
|
@@ -82,27 +85,43 @@ const useSignal = (value, opts) => {
|
|
|
82
85
|
* and updated at the same time.
|
|
83
86
|
*/
|
|
84
87
|
const useBatch = (fn) => {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
currBatch._effects = new Set();
|
|
93
|
-
effects.forEach((effect) => effect._clean?.());
|
|
94
|
-
// Run signal updates
|
|
95
|
-
currBatch._setters.forEach((setter) => setter());
|
|
96
|
-
currBatch._setters = [];
|
|
97
|
-
// Run effects
|
|
98
|
-
effects.forEach((effect) => effect._run());
|
|
99
|
-
}
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
currBatch = prevBatch;
|
|
88
|
+
const createBatch = !currBatch;
|
|
89
|
+
if (createBatch)
|
|
90
|
+
currBatch = { _setters: [], _effects: new Set() };
|
|
91
|
+
const result = fn();
|
|
92
|
+
if (createBatch) {
|
|
93
|
+
flushBatch();
|
|
94
|
+
currBatch = undefined;
|
|
104
95
|
}
|
|
96
|
+
return result;
|
|
105
97
|
};
|
|
98
|
+
function flushBatch() {
|
|
99
|
+
const mutatedSignals = new Set();
|
|
100
|
+
while (currBatch &&
|
|
101
|
+
(currBatch._setters.length > 0 || currBatch._effects.size > 0)) {
|
|
102
|
+
// Clean effect subscope
|
|
103
|
+
const effects = currBatch._effects;
|
|
104
|
+
currBatch._effects = new Set();
|
|
105
|
+
effects.forEach((effect) => effect._clean?.());
|
|
106
|
+
// Run signal updates
|
|
107
|
+
const settersCount = currBatch._setters.length;
|
|
108
|
+
for (const setter of currBatch._setters) {
|
|
109
|
+
const signal = setter();
|
|
110
|
+
mutatedSignals.add(signal);
|
|
111
|
+
}
|
|
112
|
+
currBatch._setters = [];
|
|
113
|
+
// Run effects
|
|
114
|
+
for (const effect of effects) {
|
|
115
|
+
if (!settersCount ||
|
|
116
|
+
[...effect._deps].every((dep) => mutatedSignals.has(dep))) {
|
|
117
|
+
effect._run();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
currBatch._effects.add(effect);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
106
125
|
/**
|
|
107
126
|
* Creates an effect which will rerun when any accessed signal changes.
|
|
108
127
|
*
|
|
@@ -619,12 +638,7 @@ const setAttr = (node, name, value, heuristic) => {
|
|
|
619
638
|
].includes(name) &&
|
|
620
639
|
name in node) {
|
|
621
640
|
try {
|
|
622
|
-
|
|
623
|
-
node[name] = value;
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
node[name] = value == null ? "" : value;
|
|
627
|
-
}
|
|
641
|
+
node[name] = value;
|
|
628
642
|
return;
|
|
629
643
|
}
|
|
630
644
|
catch (e) { }
|
|
@@ -1075,4 +1089,4 @@ const jsx = (type, props, key) => {
|
|
|
1075
1089
|
return createElement(type, props);
|
|
1076
1090
|
};
|
|
1077
1091
|
|
|
1078
|
-
export { Component, Else, ElseIf, For, Fragment, If, MaybeSignal, Portal, Style, createContext, createElement, css, defineComponents, event, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
|
1092
|
+
export { Component, Else, ElseIf, For, Fragment, If, MaybeSignal, Portal, Style, createContext, createElement, css, defineComponents, event, flushBatch, h, isComponent, jsx, jsx as jsxDEV, jsx as jsxs, prop, useBatch, useContext, useMountEffect as useEffect, useMemo, useRef, useSignal, useSubscope };
|
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.add(r),r.o.add(n)),r.peek());r.o=new Set,r.peek=()=>t;const c=(n,s)=>{if(s={...o,...s},e){const o="function"==typeof n?n(r.peek()):n;(s?.force||o!==r.peek())&&(s?.force?t=o:e.m.push((()=>t=o)),s?.silent||r.o.forEach((t=>e.o.add(t))))}else i((()=>c(n,s)))};return[r,c]},i=t=>{const n
|
|
1
|
+
const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.add(r),r.o.add(n)),r.peek());r.o=new Set,r.peek=()=>t;const c=(n,s)=>{if(s={...o,...s},e){const o="function"==typeof n?n(r.peek()):n;(s?.force||o!==r.peek())&&(s?.force?t=o:e.m.push((()=>(t=o,r))),s?.silent||r.o.forEach((t=>e.o.add(t))))}else i((()=>c(n,s)))};return[r,c]},i=t=>{const n=!e;n&&(e={m:[],o:new Set});const o=t();return n&&(l(),e=void 0),o};function l(){const t=new Set;for(;e&&(e.m.length>0||e.o.size>0);){const n=e.o;e.o=new Set,n.forEach((t=>t._?.()));const o=e.m.length;for(const n of e.m){const e=n();t.add(e)}e.m=[];for(const s of n)!o||[...s.p].every((n=>t.has(n)))?s.u():e.o.add(s)}}const u=(t,e)=>{const r=!!e,c={v:o,p:new Set,u(){const o=n,c=s;n=this;try{this.p.forEach((t=>t.o.delete(this))),this.p.clear(),e&&(s=!1,e.forEach((t=>t()))),s=r,this._?.();const n=this.v.u((()=>i(t)));this._=n?()=>{this.v.u((()=>i(n))),this._=null}:null}finally{n=o,s=c}}};o.o.push(c),c.u(),c.p.size||c._||o.o.pop()},f=(t,n)=>{const[e,o]=c();let s=!0;return u((()=>{o(t,s?{...n,force:!0}:n),s=!1})),e},a=(n,e)=>{const s=o,r=t(s);Object.assign(r.l,e?.details),s.i.push(r);return[r.u(n),()=>{const t=s.i.indexOf(r);t>=0&&s.i.splice(t,1),r.h()}]},d=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},h={upgrade:t=>()=>h.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},_=(t={})=>({S:[],M(t){return this.k?.next().value??t()},...t}),p=()=>{const t=r();return t.l.C??=_()},m=(t,n)=>{const e=p(),o=_({...e,...t}),[s,r]=a(n,{details:{C:o}});return u((()=>r)),s},y=t=>(t[0]??"").toLowerCase()+t.slice(1).replace(/[A-Z]/g,(t=>"-"+t.toLowerCase())),w=t=>t.startsWith("on:")?t.slice(3):y(t.slice(2)),b=Symbol(),g=(t,n)=>({[b]:Math.random().toString(36).slice(2),N:t,j:n}),v=t=>!!t?.[b],S=(t,n,e)=>{n.addEventListener(t[b],(t=>{const n=h.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))}))},x=t=>{const n=p();return f((()=>{let e=t.N;return n.H?.dispatchEvent(new CustomEvent(t[b],{detail:t=>e=t,bubbles:!0,composed:!0})),e}))},M=(t,n)=>({L:"p",T:t,...n}),k=(t=CustomEvent)=>({L:"e",A:t}),C=Symbol();let E;const N=(t,n)=>{E?E.push([t,n]):u(t,n)},j=(t,n={},e={})=>{const o=[],s=new Map;for(const t in n){const e=n[t];if("p"==e.L&&e.attribute){"function"==typeof e.attribute&&(e.attribute={transform:e.attribute});const n=e.attribute={name:y(t),static:!1,transform:t=>t,...e.attribute};s.set(n.name,{name:t,meta:e}),n.static||o.push(n.name)}}e.shadow??={mode:"open"};class i extends HTMLElement{static[C]={O:t};static observedAttributes=o;props={};events={};[C]={};constructor(){super();for(const t in n){const e=n[t];if("p"==e.L){const n=v(e.T)?e.T:null,[o,s]=c(n?void 0:e.T);this.props[t]=o,n&&S(n,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s((()=>t),{force:!0})})}else if("e"==e.L&&t.startsWith("on")){const n=w(t);this.events[t]=t=>this.dispatchEvent(new e.A(n,t))}}}connectedCallback(){const t=(n=this,e.shadow?n.shadowRoot??n.attachShadow(e.shadow):n);var n;this[C].D=a((()=>m({I:!1,H:this,k:t.childNodes.values()},(()=>{this[C].v=r();const n=E;E=[];try{t?.append(...this.render().build()),E.forEach((([t,n])=>u(t,n)))}finally{E=n}}))))[1]}disconnectedCallback(){this[C].D?.()}attributeChangedCallback(t,n,e){const o=s.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):v(o.meta.T)?void 0:o.meta.T)}}return i},H=t=>!!t?.[C],L=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+t[C].O,t)},T=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,A=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||T.test(n)?""+e:e+"px"},O=(t,n,e,o)=>{const s=null==e||!1===e&&!n.includes("-");if(n.startsWith("prop:"))t[n.slice(5)]=e;else if(n.startsWith("attr:"))n=n.slice(5),s?t.removeAttribute(n):t.setAttribute(n,e);else if(!["innerHTML","outerHTML"].includes(n)){if(!["tabIndex","role",...o?["width","height","href","list","form","download","rowSpan","colSpan"]:[]].includes(n)&&n in t)try{return void(t[n]=e)}catch(t){}"function"==typeof e||(s?t.removeAttribute(n):t.setAttribute(n,e))}},D=t=>({build(){const n=t();return n.build?.()??n}}),I=({text:t,marker:n})=>D((()=>{const e=p(),o=n&&e.M((()=>document.createComment(""))),s=e.M((()=>document.createTextNode("")));return u((()=>{const n=""+(h.get(t)??"");s.textContent!=n&&(s.textContent=n)})),o?[o,s]:[s]})),$=({children:t})=>D((()=>Array.isArray(t)?t.flatMap((t=>$({children:t}).build())):null==t?[]:"object"==typeof t?t:I({text:t}))),z=(t,n,e,o)=>{const{ref:s,style:c,children:l,dangerouslySetInnerHTML:f,...a}=e;for(const n in c??{}){const e=c[n];u((()=>{A(t,n,h.get(e))}))}for(const n in a){const e=a[n];if(n.startsWith("on")){const o=r(),s=t=>{o.u((()=>i((()=>e(t)))))},c=w(n);u((()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s))))}else u((()=>{O(t,n,h.get(e),o)}))}return f&&u((()=>{const n=h.get(f).__html;t.innerHTML!=n&&(t.innerHTML=n)})),s&&u((()=>(s.set(t),()=>s.set(void 0)))),null!=e.children&&t.append(...m({I:n,k:t.childNodes.values()},(()=>$({children:e.children}).build()))),t},P=(t,n={},e)=>(null!=e&&(n.children=e),H(t)?((t,n)=>D((()=>{const e=p().M((()=>new t));return customElements.upgrade(e),z(e,!1,n),[e]})))(t,n):"function"==typeof t?D((()=>t(n))):((t,n={})=>D((()=>{const e=p(),o="svg"==t||!!e.I;return[z(e.M((()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t))),o,n,!0)]})))(t,n)),V=new Proxy(P,{get:(t,n)=>(e,o)=>t(n,e,o)}),Z=(t,n)=>{const[e,o]=c({$:[],P:new Map});let s=new Map;return u((()=>{const e=[],r=s,c=((t,n)=>{const e=new Map;for(let o=0;o<t.length;o++){const s=n(t[o],o);if(e.has(s))throw Error(`Duplicate key '${s}'`);e.set(s,o)}return e})(t(),n),i=(t=NaN)=>e.map((t=>"r"==t.V?n=>n<t.Z?n:n==t.Z?NaN:n-1:"a"==t.V?n=>n<t.Z?n:n+1:"m"==t.V?n=>t.q<=n&&n<t.B?n+1:n==t.B?t.q:n:t=>t)).reduce(((t,n)=>n(t)),t);for(const t of r.keys()){const n=i(r.get(t));c.has(t)||e.push({V:"r",F:t,Z:n})}for(let o=0;o<t().length;o++){const s=n(t()[o],o),c=i(r.get(s));isNaN(c)?e.push({V:"a",F:s,Z:o}):c!=o&&e.push({V:"m",F:s,B:c,q:o})}e.length>0&&o({$:e,P:c}),s=c})),e},q=t=>D((()=>{const n=p(),e=h.upgrade(t.each??[]),o=n.M((()=>document.createComment(""))),s=t.key??((t,n)=>n),r=[o],i=new Map,l=Z(e,s),f=t=>{for(let n=t-1;n>=0;n--){const n=s(e()[t-1],t-1),o=i.get(n)?.G??[];if(o.length>0)return o[o.length-1]}return o};return u((()=>{for(const n of l().$)if("r"==n.V){const{G:t=[],D:e}=i.get(n.F)??{};e?.();const o=r.indexOf(t[0]);o>0&&r.splice(o,t.length),t.forEach((t=>t.parentNode?.removeChild(t))),i.delete(n.F)}else if("a"==n.V){let o=[];const[,s]=a((()=>{const[s,i]=c(n.Z),[a,d]=c(e()[n.Z]);u((()=>{0<=s()&&s()<e().length&&d((()=>e()[s()]))})),u((()=>{const t=l().P.get(n.F);null!=t&&i(t)})),o=t.children?.(a,s,e).build()??[];const h=f(n.Z),_=r.indexOf(h);_>=0&&r.splice(_+1,0,...o),o.forEach((t=>h.parentNode?.insertBefore(t,h.nextSibling)))}));i.set(n.F,{G:o,D:s})}else if("m"==n.V){const{G:t=[]}=i.get(n.F)??{},e=r.indexOf(t[0]);e>=0&&r.splice(e,t.length);const o=f(n.q),s=r.indexOf(o);s>=0&&r.splice(s+1,0,...t),t.forEach((t=>o.parentNode?.insertBefore(t,o.nextSibling)))}}),[l]),r})),B=t=>(p().S=[],F({condition:t.condition,children:t.children})),F=t=>{const n=p(),e=n.S,o=f((()=>e.every((t=>!t()))&&h.get(t.condition)));return n.S=[...e,o],m({S:[]},(()=>D((()=>{const e=n.M((()=>document.createComment(""))),s=[e],r=f((()=>o()?$({children:t.children}):null));let c=[];return u((()=>{c.forEach((t=>t.parentNode?.removeChild(t))),s.length=1;const[,t]=a((()=>{c=r()?.build()??[],e.after(...c),s.push(...c)}));return t}),[r]),s}))))},G=({children:t})=>F({condition:!0,children:t}),J=({mount:t,children:n})=>D((()=>m({k:void 0},(()=>{const e=$({children:n}).build();return u((()=>(e.forEach((n=>t.appendChild(n))),()=>{e.forEach((t=>t.parentNode?.removeChild(t)))}))),[]})))),K=Symbol(),Q=new Map,R=t=>{const n=t.children;if("function"==typeof n){const e=P("style",{},I({text:n,marker:!1}));return t.light?J({mount:document.head,children:e}):e}if(n){const o=p(),s=t.light?document:o.H?.shadowRoot??document,r=((t,n,e)=>{if(!Q.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),Q.set(n,{J:t,K:0})}const o=Q.get(n);o.K++,t.has(n)||t.set(n,{J:o.J,K:0});const s=t.get(n);return s.K++,u((()=>()=>{--s.K||(t.delete(n),e()),--o.K||Q.delete(n)})),s.J})((e=s,e[K]??=new Map),n,(()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter((t=>t!=r))}));s.adoptedStyleSheets.push(r)}var e;return $({})},U=(t,...n)=>{const e=()=>t.reduce(((t,e,o)=>t+e+(h.get(n[o])??"")),"");return n.some((t=>"function"==typeof t))?e:e()},W=(t,n,e)=>(n&&null!=e&&(n.key=e),P(t,n));export{j as Component,G as Else,F as ElseIf,q as For,$ as Fragment,B as If,h as MaybeSignal,J as Portal,R as Style,g as createContext,P as createElement,U as css,L as defineComponents,k as event,l as flushBatch,V as h,H as isComponent,W as jsx,W as jsxDEV,W as jsxs,M as prop,i as useBatch,x as useContext,N as useEffect,f as useMemo,d as useRef,c as useSignal,a as useSubscope};
|
package/dist/dom.js
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
|
-
import { isComponent } from "./component.js";
|
|
28
27
|
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
29
28
|
export const setStyle = (node, key, value) => {
|
|
30
29
|
if (key[0] == "-") {
|
|
@@ -74,12 +73,7 @@ export const setAttr = (node, name, value, heuristic) => {
|
|
|
74
73
|
].includes(name) &&
|
|
75
74
|
name in node) {
|
|
76
75
|
try {
|
|
77
|
-
|
|
78
|
-
node[name] = value;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
node[name] = value == null ? "" : value;
|
|
82
|
-
}
|
|
76
|
+
node[name] = value;
|
|
83
77
|
return;
|
|
84
78
|
}
|
|
85
79
|
catch (e) { }
|
package/dist/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sourceRoot":"","sources":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|
3
3
|
export { createElement, h } from "./create_element.js";
|
|
4
4
|
export { DangerousHtml, Styles } from "./dom.js";
|
|
5
5
|
export { type Template } from "./template.js";
|
|
6
|
-
export { type Cleanup, MaybeSignal, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, type SubscopeOptions, type RefSignal, type RefSignalSetter,
|
|
6
|
+
export { type Cleanup, MaybeSignal, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, type SubscopeOptions, type RefSignal, type RefSignalSetter, useSubscope, useMemo, useSignal, useRef, useBatch, flushBatch, } from "./scope.js";
|
|
7
7
|
export * from "./intrinsic/mod.js";
|
|
8
8
|
export * from "./jsx-runtime/mod.js";
|
package/dist/mod.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Component, defineComponents, event, isComponent, prop, useMountEffect as useEffect, } from "./component.js";
|
|
2
2
|
export { createContext, useContext } from "./context.js";
|
|
3
3
|
export { createElement, h } from "./create_element.js";
|
|
4
|
-
export { MaybeSignal,
|
|
4
|
+
export { MaybeSignal, useSubscope, useMemo, useSignal, useRef, useBatch, flushBatch, } from "./scope.js";
|
|
5
5
|
export * from "./intrinsic/mod.js";
|
|
6
6
|
export * from "./jsx-runtime/mod.js";
|
|
7
7
|
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAGT,gBAAgB,EAChB,KAAK,EAGL,WAAW,EAEX,IAAI,EAEJ,cAAc,IAAI,SAAS,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAEL,WAAW,EAQX,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAGT,gBAAgB,EAChB,KAAK,EAGL,WAAW,EAEX,IAAI,EAEJ,cAAc,IAAI,SAAS,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAEL,WAAW,EAQX,WAAW,EACX,OAAO,EACP,SAAS,EACT,MAAM,EACN,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
package/dist/scope.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare const useSignal: (<T>(value: T, opts?: SetSignalOptions) => reado
|
|
|
71
71
|
* and updated at the same time.
|
|
72
72
|
*/
|
|
73
73
|
export declare const useBatch: <T>(fn: () => T) => T;
|
|
74
|
+
export declare function flushBatch(): void;
|
|
74
75
|
/**
|
|
75
76
|
* Creates an effect which will rerun when any accessed signal changes.
|
|
76
77
|
*
|
package/dist/scope.js
CHANGED
|
@@ -62,7 +62,10 @@ export const useSignal = (value, opts) => {
|
|
|
62
62
|
value = newValue;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
currBatch._setters.push(() =>
|
|
65
|
+
currBatch._setters.push(() => {
|
|
66
|
+
value = newValue;
|
|
67
|
+
return signal;
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
if (!innerOpts?.silent) {
|
|
68
71
|
signal._effects.forEach((effect) => currBatch._effects.add(effect));
|
|
@@ -82,27 +85,43 @@ export const useSignal = (value, opts) => {
|
|
|
82
85
|
* and updated at the same time.
|
|
83
86
|
*/
|
|
84
87
|
export const useBatch = (fn) => {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
currBatch._effects = new Set();
|
|
93
|
-
effects.forEach((effect) => effect._clean?.());
|
|
94
|
-
// Run signal updates
|
|
95
|
-
currBatch._setters.forEach((setter) => setter());
|
|
96
|
-
currBatch._setters = [];
|
|
97
|
-
// Run effects
|
|
98
|
-
effects.forEach((effect) => effect._run());
|
|
99
|
-
}
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
currBatch = prevBatch;
|
|
88
|
+
const createBatch = !currBatch;
|
|
89
|
+
if (createBatch)
|
|
90
|
+
currBatch = { _setters: [], _effects: new Set() };
|
|
91
|
+
const result = fn();
|
|
92
|
+
if (createBatch) {
|
|
93
|
+
flushBatch();
|
|
94
|
+
currBatch = undefined;
|
|
104
95
|
}
|
|
96
|
+
return result;
|
|
105
97
|
};
|
|
98
|
+
export function flushBatch() {
|
|
99
|
+
const mutatedSignals = new Set();
|
|
100
|
+
while (currBatch &&
|
|
101
|
+
(currBatch._setters.length > 0 || currBatch._effects.size > 0)) {
|
|
102
|
+
// Clean effect subscope
|
|
103
|
+
const effects = currBatch._effects;
|
|
104
|
+
currBatch._effects = new Set();
|
|
105
|
+
effects.forEach((effect) => effect._clean?.());
|
|
106
|
+
// Run signal updates
|
|
107
|
+
const settersCount = currBatch._setters.length;
|
|
108
|
+
for (const setter of currBatch._setters) {
|
|
109
|
+
const signal = setter();
|
|
110
|
+
mutatedSignals.add(signal);
|
|
111
|
+
}
|
|
112
|
+
currBatch._setters = [];
|
|
113
|
+
// Run effects
|
|
114
|
+
for (const effect of effects) {
|
|
115
|
+
if (!settersCount ||
|
|
116
|
+
[...effect._deps].every((dep) => mutatedSignals.has(dep))) {
|
|
117
|
+
effect._run();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
currBatch._effects.add(effect);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
106
125
|
/**
|
|
107
126
|
* Creates an effect which will rerun when any accessed signal changes.
|
|
108
127
|
*
|
package/dist/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAsEA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAS,EAAE;IAC5C,OAAO;QACL,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE;QAEjC,IAAI,CAAI,EAAW;YACjB,MAAM,SAAS,GAAG,SAAS,CAAC;YAC5B,SAAS,GAAG,IAAI,CAAC;YAEjB,IAAI,CAAC;gBACH,OAAO,EAAE,EAAE,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,SAAS,GAAG,SAAS,CAAC;YACxB,CAAC;QACH,CAAC;QAED,QAAQ;YACN,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACrD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YAChC,CAAC;YAED,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;YAErB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACnD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAChC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;gBAClB,MAAM,CAAC,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAsEA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAS,EAAE;IAC5C,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IAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAmC,CAAC,GAAG,GAAG,MAAM,CAAC;IAClD,OAAO,MAAiD,CAAC;AAC3D,CAAC,CAAC;AASF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB;;OAEG;IACH,OAAO,EACL,CAAI,MAAsB,EAAiB,EAAE,CAC7C,GAAG,EAAE,CACH,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC;IAE3B;;OAEG;IACH,GAAG,EAAE,CAAI,MAAsB,EAAK,EAAE,CACpC,OAAO,MAAM,IAAI,UAAU,CAAC,CAAC,CAAE,MAAwB,EAAE,CAAC,CAAC,CAAC,MAAM;IAEpE;;OAEG;IACH,IAAI,CAAI,MAAsB;QAC5B,MAAM,aAAa,GAAG,aAAa,CAAC;QACpC,aAAa,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;gBAAS,CAAC;YACT,aAAa,GAAG,aAAa,CAAC;QAChC,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
package/src/dom.ts
CHANGED
package/src/mod.ts
CHANGED
|
@@ -27,11 +27,12 @@ export {
|
|
|
27
27
|
type SubscopeOptions,
|
|
28
28
|
type RefSignal,
|
|
29
29
|
type RefSignalSetter,
|
|
30
|
-
|
|
30
|
+
useSubscope,
|
|
31
31
|
useMemo,
|
|
32
32
|
useSignal,
|
|
33
33
|
useRef,
|
|
34
|
-
|
|
34
|
+
useBatch,
|
|
35
|
+
flushBatch,
|
|
35
36
|
} from "./scope.js";
|
|
36
37
|
|
|
37
38
|
export * from "./intrinsic/mod.js";
|
package/src/scope.ts
CHANGED
|
@@ -96,7 +96,7 @@ const createScope = (parent?: Scope): Scope => {
|
|
|
96
96
|
for (let i = this._effects.length - 1; i >= 0; i--) {
|
|
97
97
|
const effect = this._effects[i];
|
|
98
98
|
effect._clean?.();
|
|
99
|
-
effect._run = () => {}
|
|
99
|
+
effect._run = () => {};
|
|
100
100
|
|
|
101
101
|
effect._deps.forEach((signal) => signal._effects.delete(effect));
|
|
102
102
|
effect._deps.clear();
|
|
@@ -113,7 +113,7 @@ let currUntracked: boolean = false;
|
|
|
113
113
|
let currEffect: Effect | undefined;
|
|
114
114
|
let currBatch:
|
|
115
115
|
| {
|
|
116
|
-
_setters: (() =>
|
|
116
|
+
_setters: (() => Signal<unknown>)[];
|
|
117
117
|
_effects: Set<Effect>;
|
|
118
118
|
}
|
|
119
119
|
| undefined;
|
|
@@ -161,7 +161,10 @@ export const useSignal: (<T>(
|
|
|
161
161
|
if (innerOpts?.force) {
|
|
162
162
|
value = newValue;
|
|
163
163
|
} else {
|
|
164
|
-
currBatch._setters.push(() =>
|
|
164
|
+
currBatch._setters.push(() => {
|
|
165
|
+
value = newValue;
|
|
166
|
+
return signal;
|
|
167
|
+
});
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
if (!innerOpts?.silent) {
|
|
@@ -183,35 +186,58 @@ export const useSignal: (<T>(
|
|
|
183
186
|
* and updated at the same time.
|
|
184
187
|
*/
|
|
185
188
|
export const useBatch = <T>(fn: () => T): T => {
|
|
186
|
-
const
|
|
187
|
-
currBatch = { _setters: [], _effects: new Set() };
|
|
189
|
+
const createBatch = !currBatch;
|
|
190
|
+
if (createBatch) currBatch = { _setters: [], _effects: new Set() };
|
|
188
191
|
|
|
189
|
-
|
|
190
|
-
const result = fn();
|
|
192
|
+
const result = fn();
|
|
191
193
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
if (createBatch) {
|
|
195
|
+
flushBatch();
|
|
196
|
+
currBatch = undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return result;
|
|
200
|
+
};
|
|
194
201
|
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
export function flushBatch(): void {
|
|
203
|
+
const mutatedSignals = new Set<Signal<unknown>>();
|
|
197
204
|
|
|
198
|
-
|
|
205
|
+
while (
|
|
206
|
+
currBatch &&
|
|
207
|
+
(currBatch._setters.length > 0 || currBatch._effects.size > 0)
|
|
208
|
+
) {
|
|
209
|
+
// Clean effect subscope
|
|
199
210
|
|
|
200
|
-
|
|
211
|
+
const effects = currBatch._effects;
|
|
212
|
+
currBatch._effects = new Set();
|
|
201
213
|
|
|
202
|
-
|
|
203
|
-
currBatch._setters = [];
|
|
214
|
+
effects.forEach((effect) => effect._clean?.());
|
|
204
215
|
|
|
205
|
-
|
|
216
|
+
// Run signal updates
|
|
206
217
|
|
|
207
|
-
|
|
218
|
+
const settersCount = currBatch._setters.length;
|
|
219
|
+
|
|
220
|
+
for (const setter of currBatch._setters) {
|
|
221
|
+
const signal = setter();
|
|
222
|
+
mutatedSignals.add(signal);
|
|
208
223
|
}
|
|
209
224
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
225
|
+
currBatch._setters = [];
|
|
226
|
+
|
|
227
|
+
// Run effects
|
|
228
|
+
|
|
229
|
+
for (const effect of effects) {
|
|
230
|
+
if (
|
|
231
|
+
!settersCount ||
|
|
232
|
+
[...effect._deps].every((dep) => mutatedSignals.has(dep))
|
|
233
|
+
) {
|
|
234
|
+
effect._run();
|
|
235
|
+
} else {
|
|
236
|
+
currBatch._effects.add(effect);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
213
239
|
}
|
|
214
|
-
}
|
|
240
|
+
}
|
|
215
241
|
|
|
216
242
|
/**
|
|
217
243
|
* Creates an effect which will rerun when any accessed signal changes.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { FunctionalComponent } from "../component.js";
|
|
2
|
-
import { MaybeSignal } from "../scope.js";
|
|
3
|
-
import { Template } from "../template.js";
|
|
4
|
-
/**
|
|
5
|
-
* `Dynamic` is a component that can be used to render conditionally.
|
|
6
|
-
*
|
|
7
|
-
* On every change, it will replace all previously rendered nodes with new ones.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const App = () => (
|
|
12
|
-
* const [count, setCount] = useSignal(100);
|
|
13
|
-
*
|
|
14
|
-
* <Dynamic
|
|
15
|
-
* render={() =>
|
|
16
|
-
* count() === 1 ? (
|
|
17
|
-
* <>
|
|
18
|
-
* <h3>Details</h3>
|
|
19
|
-
* { … }
|
|
20
|
-
* </>
|
|
21
|
-
* ) : count() > 1 ? (
|
|
22
|
-
* <p>Multiple items selected</p>
|
|
23
|
-
* ) : (
|
|
24
|
-
* <p>No items</p>
|
|
25
|
-
* )
|
|
26
|
-
* }
|
|
27
|
-
* />
|
|
28
|
-
* );
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare const Dynamic: FunctionalComponent<{
|
|
32
|
-
render?: MaybeSignal<Template | undefined | void | null>;
|
|
33
|
-
}>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
|
|
2
|
-
import { useRenderer } from "../renderer.js";
|
|
3
|
-
import { createTemplate } from "../template.js";
|
|
4
|
-
/**
|
|
5
|
-
* `Dynamic` is a component that can be used to render conditionally.
|
|
6
|
-
*
|
|
7
|
-
* On every change, it will replace all previously rendered nodes with new ones.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const App = () => (
|
|
12
|
-
* const [count, setCount] = useSignal(100);
|
|
13
|
-
*
|
|
14
|
-
* <Dynamic
|
|
15
|
-
* render={() =>
|
|
16
|
-
* count() === 1 ? (
|
|
17
|
-
* <>
|
|
18
|
-
* <h3>Details</h3>
|
|
19
|
-
* { … }
|
|
20
|
-
* </>
|
|
21
|
-
* ) : count() > 1 ? (
|
|
22
|
-
* <p>Multiple items selected</p>
|
|
23
|
-
* ) : (
|
|
24
|
-
* <p>No items</p>
|
|
25
|
-
* )
|
|
26
|
-
* }
|
|
27
|
-
* />
|
|
28
|
-
* );
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const Dynamic = (props) => createTemplate(() => {
|
|
32
|
-
const renderer = useRenderer();
|
|
33
|
-
const anchor = renderer._node(() => document.createComment(""));
|
|
34
|
-
const nodes = [anchor];
|
|
35
|
-
const template = useMemo(() => MaybeSignal.get(props.render));
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const [subnodes, destroy] = useSubscope(() => {
|
|
38
|
-
const subnodes = template()?.build() ?? [];
|
|
39
|
-
anchor.after(...subnodes);
|
|
40
|
-
nodes.push(...subnodes);
|
|
41
|
-
return subnodes;
|
|
42
|
-
});
|
|
43
|
-
return () => {
|
|
44
|
-
destroy();
|
|
45
|
-
for (const node of subnodes ?? []) {
|
|
46
|
-
node.parentNode?.removeChild(node);
|
|
47
|
-
}
|
|
48
|
-
nodes.length = 1;
|
|
49
|
-
};
|
|
50
|
-
}, [template]);
|
|
51
|
-
return nodes;
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=Dynamic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Dynamic.js","sourceRoot":"","sources":["../../src/intrinsic/Dynamic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAY,MAAM,gBAAgB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,OAAO,GAEf,CAAC,KAAK,EAAE,EAAE,CACb,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE;YAC3C,MAAM,QAAQ,GAAG,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAC3C,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC;YAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAC;YAEV,KAAK,MAAM,IAAI,IAAI,QAAQ,IAAI,EAAE,EAAE,CAAC;gBAClC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YAED,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FunctionalComponent } from "../component.js";
|
|
2
|
-
import { Children } from "./Fragment.js";
|
|
3
|
-
/**
|
|
4
|
-
* `ErrorBoundary` is a component that can be used to catch errors in the
|
|
5
|
-
* component tree.
|
|
6
|
-
*/
|
|
7
|
-
export declare const ErrorBoundary: FunctionalComponent<{
|
|
8
|
-
fallback?: FunctionalComponent<{
|
|
9
|
-
error: unknown;
|
|
10
|
-
reset: () => void;
|
|
11
|
-
}>;
|
|
12
|
-
children?: Children;
|
|
13
|
-
}>;
|
|
14
|
-
export declare const useErrorBoundary: () => readonly [show: (err: unknown) => void, reset: () => void];
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useScope, useSignal } from "../scope.js";
|
|
2
|
-
import { createTemplate } from "../template.js";
|
|
3
|
-
import { Fragment } from "./Fragment.js";
|
|
4
|
-
import { createContext, provideContext, useContext } from "../context.js";
|
|
5
|
-
import { If } from "./If.js";
|
|
6
|
-
const ErrorContext = createContext([
|
|
7
|
-
(err) => {
|
|
8
|
-
throw err;
|
|
9
|
-
},
|
|
10
|
-
() => { },
|
|
11
|
-
]);
|
|
12
|
-
/**
|
|
13
|
-
* `ErrorBoundary` is a component that can be used to catch errors in the
|
|
14
|
-
* component tree.
|
|
15
|
-
*/
|
|
16
|
-
export const ErrorBoundary = ({ fallback, children }) => {
|
|
17
|
-
let error;
|
|
18
|
-
const [showError, setShowError] = useSignal(false);
|
|
19
|
-
const show = (err) => {
|
|
20
|
-
error = err;
|
|
21
|
-
setShowError(true);
|
|
22
|
-
};
|
|
23
|
-
const reset = () => setShowError(false);
|
|
24
|
-
return If({
|
|
25
|
-
condition: showError,
|
|
26
|
-
then: createTemplate(() => fallback?.({ error, reset }) ?? []),
|
|
27
|
-
else: createTemplate(() => {
|
|
28
|
-
provideContext(ErrorContext, () => [show, reset]);
|
|
29
|
-
const s = useScope();
|
|
30
|
-
s._onError = show;
|
|
31
|
-
return Fragment({ children });
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
export const useErrorBoundary = () => useContext(ErrorContext)();
|
|
36
|
-
//# sourceMappingURL=ErrorBoundary.js.map
|