@firsthandjs/core 0.8.0 → 0.9.1
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/core.d.ts +22 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/effect.d.ts +3 -0
- package/dist/effect.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.dev.js +45 -5
- package/dist/index.js +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -84,6 +84,28 @@ export declare function disposeCell(cell: Cell): void;
|
|
|
84
84
|
export declare function handleError(error: unknown, owner: Owner | null): void;
|
|
85
85
|
export declare function getOwner(): Owner | null;
|
|
86
86
|
export declare function setOwner(owner: Owner | null): Owner | null;
|
|
87
|
+
/**
|
|
88
|
+
* Puts off creating a scope until something needs one.
|
|
89
|
+
*
|
|
90
|
+
* A scope exists so that what a component makes can be taken apart again. A
|
|
91
|
+
* component that makes nothing — no signal, no effect, no context, no cleanup
|
|
92
|
+
* — has nothing to take apart, and on a server most of them are exactly that:
|
|
93
|
+
* a function that reads its props and returns markup. Creating an owner for
|
|
94
|
+
* each of them, linking it into its parent and walking the lot on disposal
|
|
95
|
+
* measured at a sixth of a server render.
|
|
96
|
+
*
|
|
97
|
+
* So the scope is described rather than created. The first thing that asks for
|
|
98
|
+
* one gets one, with the right parent; a component that never asks costs
|
|
99
|
+
* nothing at all.
|
|
100
|
+
*
|
|
101
|
+
* Returns the owner to hand back to `restoreOwner`. The parent is made here
|
|
102
|
+
* rather than deferred in turn, which is what makes that one value enough to
|
|
103
|
+
* restore from — and is no loss, because a component that has children is a
|
|
104
|
+
* component that has a scope.
|
|
105
|
+
*/
|
|
106
|
+
export declare function deferOwner(): Owner | null;
|
|
107
|
+
/** Ends a `deferOwner`, whether or not the scope was ever made. */
|
|
108
|
+
export declare function restoreOwner(previous: Owner | null): void;
|
|
87
109
|
/** Registers a cell with the current scope so disposal unlinks it. */
|
|
88
110
|
export declare function own(cell: Cell): void;
|
|
89
111
|
export declare function createEffectScope(cell: Cell): Owner;
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAiBH;oCACoC;AACpC,qBAAa,IAAI;IACP,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,IAAI,CAAC;IACV,OAAO,EAAE,IAAI,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,SAAS,CAAC;gBAGhC,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,OAAO,EAAE,IAAI,GAAG,SAAS,EACzB,OAAO,EAAE,IAAI,GAAG,SAAS,EACzB,OAAO,EAAE,IAAI,GAAG,SAAS;CAS5B;AAOD;;;GAGG;AACH,qBAAa,IAAI;IACP,KAAK,EAAE,MAAM,CAAC;IACtB,oDAAoD;IAC5C,CAAC,EAAE,OAAO,CAAC;IACnB,8DAA8D;IACtD,EAAE,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;IAC5C,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;IACnC,6EAA6E;IACrE,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAG/B,KAAK,EAAE,MAAM,EACb,KAAK,EAA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AkBG;AACH,wBAAgB,UAAU,IAAI,KAAK,GAAG,IAAI,CAMzC;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAIzD;AAED,sEAAsE;AACtE,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKpC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAInD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAW9C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC7B,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,KAAK,GAAG,SAAS,GACpD,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAO,CAQrC;AAMD,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CASvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAO5C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQzC"}
|
package/dist/effect.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ type EffectBody = () => void | (() => void);
|
|
|
13
13
|
* 100 000 rows that closure would be 100 000 objects for nothing.
|
|
14
14
|
*/
|
|
15
15
|
export declare function createEffect(fn: EffectBody): Cell;
|
|
16
|
+
/** Set by `@firsthandjs/server` around a render. Not part of the public API. */
|
|
17
|
+
export declare function setRendering(on: boolean): boolean;
|
|
18
|
+
export declare function isRendering(): boolean;
|
|
16
19
|
/**
|
|
17
20
|
* Runs `fn` once inside a tracking scope and keeps an effect only if the run
|
|
18
21
|
* actually read something reactive.
|
package/dist/effect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAOL,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;GAGG;AAEH,KAAK,UAAU,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAOL,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;GAGG;AAEH,KAAK,UAAU,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CASjD;AAcD,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAIjD;AAED,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAKzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CAW9C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { FirsthandCycleError, FirsthandContextError, FirsthandReadonlyError } fr
|
|
|
16
16
|
export type { CellOptions, DeepReadonly, DevtoolsHook, Dispose, ReadonlyCell, ReadonlyProps, Signal, } from './types.js';
|
|
17
17
|
export type { Owner } from './core.js';
|
|
18
18
|
/** Internal surface used by `@firsthandjs/dom`; not part of the public contract. */
|
|
19
|
-
export { createEffect, bind } from './effect.js';
|
|
19
|
+
export { createEffect, bind, setRendering, isRendering } from './effect.js';
|
|
20
20
|
export { devEnterSetup, devExitSetup } from './dev.js';
|
|
21
|
-
export { Cell, createOwner, disposeOwner, disposeCell, handleError, own, setOwner, } from './core.js';
|
|
21
|
+
export { Cell, createOwner, disposeOwner, disposeCell, handleError, own, setOwner, deferOwner, restoreOwner, } from './core.js';
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjG,YAAY,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,YAA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AAC"}
|
package/dist/index.dev.js
CHANGED
|
@@ -150,6 +150,8 @@ var Cell = class {
|
|
|
150
150
|
};
|
|
151
151
|
var activeSub;
|
|
152
152
|
var currentOwner = null;
|
|
153
|
+
var deferred = false;
|
|
154
|
+
var deferredParent = null;
|
|
153
155
|
var batchDepth = 0;
|
|
154
156
|
var flushing = false;
|
|
155
157
|
var queueIndex = 0;
|
|
@@ -323,8 +325,10 @@ function checkDirty(cell) {
|
|
|
323
325
|
function evaluate(cell) {
|
|
324
326
|
const prevSub = activeSub;
|
|
325
327
|
const prevOwner = currentOwner;
|
|
328
|
+
const prevDeferred = deferred;
|
|
326
329
|
activeSub = cell;
|
|
327
330
|
currentOwner = null;
|
|
331
|
+
deferred = false;
|
|
328
332
|
startTracking(cell);
|
|
329
333
|
try {
|
|
330
334
|
const next = cell.fn();
|
|
@@ -338,6 +342,7 @@ function evaluate(cell) {
|
|
|
338
342
|
endTracking(cell);
|
|
339
343
|
activeSub = prevSub;
|
|
340
344
|
currentOwner = prevOwner;
|
|
345
|
+
deferred = prevDeferred;
|
|
341
346
|
}
|
|
342
347
|
}
|
|
343
348
|
function enqueue(cell) {
|
|
@@ -376,8 +381,10 @@ function runEffect(cell) {
|
|
|
376
381
|
clearScope(scope);
|
|
377
382
|
const prevSub = activeSub;
|
|
378
383
|
const prevOwner = currentOwner;
|
|
384
|
+
const prevDeferred = deferred;
|
|
379
385
|
activeSub = cell;
|
|
380
386
|
currentOwner = scope;
|
|
387
|
+
deferred = false;
|
|
381
388
|
startTracking(cell);
|
|
382
389
|
devRunning(cell);
|
|
383
390
|
try {
|
|
@@ -392,6 +399,7 @@ function runEffect(cell) {
|
|
|
392
399
|
endTracking(cell);
|
|
393
400
|
activeSub = prevSub;
|
|
394
401
|
currentOwner = prevOwner;
|
|
402
|
+
deferred = prevDeferred;
|
|
395
403
|
}
|
|
396
404
|
}
|
|
397
405
|
function createOwner(parent) {
|
|
@@ -512,21 +520,38 @@ function handleError(error, owner) {
|
|
|
512
520
|
reportUncaught(error);
|
|
513
521
|
}
|
|
514
522
|
function getOwner() {
|
|
523
|
+
if (deferred) {
|
|
524
|
+
currentOwner = createOwner(deferredParent);
|
|
525
|
+
deferred = false;
|
|
526
|
+
}
|
|
515
527
|
return currentOwner;
|
|
516
528
|
}
|
|
517
529
|
function setOwner(owner) {
|
|
518
|
-
const previous =
|
|
530
|
+
const previous = getOwner();
|
|
519
531
|
currentOwner = owner;
|
|
532
|
+
deferred = false;
|
|
520
533
|
return previous;
|
|
521
534
|
}
|
|
535
|
+
function deferOwner() {
|
|
536
|
+
const parent = getOwner();
|
|
537
|
+
deferredParent = parent;
|
|
538
|
+
deferred = true;
|
|
539
|
+
currentOwner = null;
|
|
540
|
+
return parent;
|
|
541
|
+
}
|
|
542
|
+
function restoreOwner(previous) {
|
|
543
|
+
currentOwner = previous;
|
|
544
|
+
deferred = false;
|
|
545
|
+
deferredParent = null;
|
|
546
|
+
}
|
|
522
547
|
function own(cell) {
|
|
523
|
-
const owner =
|
|
548
|
+
const owner = getOwner();
|
|
524
549
|
if (owner !== null) {
|
|
525
550
|
(owner.cells ??= []).push(cell);
|
|
526
551
|
}
|
|
527
552
|
}
|
|
528
553
|
function createEffectScope(cell) {
|
|
529
|
-
const scope = createOwner(
|
|
554
|
+
const scope = createOwner(getOwner());
|
|
530
555
|
cell.scope = scope;
|
|
531
556
|
return scope;
|
|
532
557
|
}
|
|
@@ -536,7 +561,7 @@ function runEffectNow(cell) {
|
|
|
536
561
|
function releaseEffect(cell) {
|
|
537
562
|
cell.flags |= DISPOSED;
|
|
538
563
|
cell.fn = void 0;
|
|
539
|
-
const owner =
|
|
564
|
+
const owner = getOwner();
|
|
540
565
|
if (owner !== null) {
|
|
541
566
|
const cells = owner.cells;
|
|
542
567
|
cells.pop();
|
|
@@ -600,9 +625,20 @@ function createEffect(fn) {
|
|
|
600
625
|
devLabel(cell, "effect", fn.name);
|
|
601
626
|
own(cell);
|
|
602
627
|
createEffectScope(cell);
|
|
603
|
-
|
|
628
|
+
if (!rendering) {
|
|
629
|
+
runEffectNow(cell);
|
|
630
|
+
}
|
|
604
631
|
return cell;
|
|
605
632
|
}
|
|
633
|
+
var rendering = false;
|
|
634
|
+
function setRendering(on) {
|
|
635
|
+
const previous = rendering;
|
|
636
|
+
rendering = on;
|
|
637
|
+
return previous;
|
|
638
|
+
}
|
|
639
|
+
function isRendering() {
|
|
640
|
+
return rendering;
|
|
641
|
+
}
|
|
606
642
|
function bind(fn) {
|
|
607
643
|
const cell = createEffect(fn);
|
|
608
644
|
if (cell.deps === void 0) {
|
|
@@ -730,6 +766,7 @@ export {
|
|
|
730
766
|
createEffect,
|
|
731
767
|
createOwner,
|
|
732
768
|
createRoot,
|
|
769
|
+
deferOwner,
|
|
733
770
|
devEnterSetup,
|
|
734
771
|
devExitSetup,
|
|
735
772
|
disposeCell,
|
|
@@ -737,11 +774,14 @@ export {
|
|
|
737
774
|
effect,
|
|
738
775
|
getOwner,
|
|
739
776
|
handleError,
|
|
777
|
+
isRendering,
|
|
740
778
|
onCleanup,
|
|
741
779
|
own,
|
|
742
780
|
provide,
|
|
781
|
+
restoreOwner,
|
|
743
782
|
runWithOwner,
|
|
744
783
|
setOwner,
|
|
784
|
+
setRendering,
|
|
745
785
|
setStrictReactivity,
|
|
746
786
|
signal,
|
|
747
787
|
snapshot,
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=class extends Error{constructor(){super("Reactive update did not settle: an effect keeps invalidating its own dependencies. Use untrack() or batch() to break the cycle."),this.name="FirsthandCycleError"}},w=class extends Error{constructor(n){super(`No provider for ${n}, and the context was created without a default value.`),this.name="FirsthandContextError"}},x=class extends Error{constructor(){super("Cannot assign to a computed value. Write to the signals it derives from instead."),this.name="FirsthandReadonlyError"}};function A(e){queueMicrotask(()=>{throw e})}function ne(e){}function te(e){}function oe(){}var L=class{constructor(n,t,o,r,i){this.dep=n,this.sub=t,this.prevDep=o,this.nextDep=r,this.prevSub=i,this.nextSub=void 0}},ie=Object.is,le=()=>!1,s=class{constructor(n,t,o,r){this.flags=n,this.v=t,this.fn=o,this.equals=r,this.deps=void 0,this.depsTail=void 0,this.subs=void 0,this.subsTail=void 0,this.scope=void 0}get value(){let n=this.flags;return(n&1)!==0&&(n&12)!==0&&_(this),u!==void 0?ue(this,u):void 0,this.v}set value(n){if((this.flags&1)!==0)throw new x;F(this,n)}peek(){let n=this.flags;return(n&1)!==0&&(n&12)!==0&&_(this),this.v}set(n){if((this.flags&1)!==0)throw new x;F(this,n(this.v))}},u,d=null,f=!1,I=null,j=0,D=!1,k=0,C=[],se=1e6;function ue(e,n){let t=n.depsTail;if(t!==void 0&&t.dep===e)return;let o=t!==void 0?t.nextDep:n.deps;if(o!==void 0&&o.dep===e){n.depsTail=o;return}let r=e.subsTail;if(r!==void 0&&r.sub===n&&de(r,n))return;let i=new L(e,n,t,o,r);n.depsTail=i,e.subsTail=i,o!==void 0&&(o.prevDep=i),t!==void 0?t.nextDep=i:n.deps=i,r!==void 0?r.nextSub=i:e.subs=i}function de(e,n){let t=n.depsTail;for(;t!==void 0;){if(t===e)return!0;t=t.prevDep}return!1}function q(e,n){let t=e.dep,o=e.prevDep,r=e.nextDep,i=e.prevSub,T=e.nextSub;return r!==void 0?r.prevDep=o:n.depsTail=o,o!==void 0?o.nextDep=r:n.deps=r,T!==void 0?T.prevSub=i:t.subsTail=i,i!==void 0?i.nextSub=T:t.subs=T,r}function P(e){e.depsTail=void 0,e.flags&=-13}function H(e){let n=e.depsTail,t=n!==void 0?n.nextDep:e.deps;for(;t!==void 0;)t=q(t,e)}function fe(e){let n=e;do{let t=n.sub,o=t.flags;(o&4)===0&&(t.flags=o|4,(o&8)===0&&((o&2)!==0?G(t):t.subs!==void 0&&M(t.subs))),n=n.nextSub}while(n!==void 0)}function M(e){let n=e;do{let t=n.sub,o=t.flags;(o&12)===0&&(t.flags=o|8,(o&2)!==0?G(t):t.subs!==void 0&&M(t.subs)),n=n.nextSub}while(n!==void 0)}function ae(e){let n=e;do{let t=n.sub,o=t.flags;(o&12)===8&&(t.flags=o|4),n=n.nextSub}while(n!==void 0)}function F(e,n){if(e.equals(e.v,n))return;e.v=n;let t=e.subs;t!==void 0&&(fe(t),j===0&&Y())}function _(e){if((e.flags&4)!==0||V(e)){if(!ce(e))return!1;let t=e.subs;return t!==void 0&&t.nextSub!==void 0&&ae(t),!0}return e.flags=e.flags&-9,!1}function V(e){let n=e.deps;for(;n!==void 0;){let t=n.dep;if((t.flags&1)!==0&&(t.flags&12)!==0&&_(t))return!0;n=n.nextDep}return!1}function ce(e){let n=u,t=d,o=f;u=e,d=null,f=!1,P(e);try{let r=e.fn();return(e.flags&32)!==0&&e.equals(e.v,r)?!1:(e.flags|=32,e.v=r,!0)}finally{H(e),u=n,d=t,f=o}}function G(e){C.push(e)}function Y(){if(D)return;D=!0;let e=0;try{for(;k<C.length;){let n=C[k];if(C[k++]=void 0,(n.flags&16)===0){if(++e>se)throw new p;(n.flags&4)!==0||V(n)?$(n):n.flags&=-9}}}finally{C.length=0,k=0,D=!1}}function $(e){let n=e.scope;N(n);let t=u,o=d,r=f;u=e,d=n,f=!1,P(e);try{let i=e.fn();typeof i=="function"&&(n.disposals??=[]).push(i)}catch(i){h(i,n)}finally{H(e),u=t,d=o,f=r}}function v(e){let n={parent:e,attached:e!==null,prev:null,next:null,head:null,tail:null,disposals:null,cells:null,ctx:e!==null?e.ctx:null,handler:null};if(e!==null){let t=e.tail;n.prev=t,t!==null?t.next=n:e.head=n,e.tail=n}return n}function N(e){let n=e.head;for(;n!==null;){let r=n.next;n.attached=!1,n.prev=null,n.next=null,N(n),n=r}e.head=null,e.tail=null,e.ctx=e.parent!==null?e.parent.ctx:null;let t=e.cells;if(t!==null){for(let r=t.length-1;r>=0;r--)S(t[r]);e.cells=null}let o=e.disposals;if(o!==null){e.disposals=null;for(let r=o.length-1;r>=0;r--)try{o[r]()}catch(i){h(i,e)}}}function E(e){if(e.attached){let n=e.parent,t=e.prev,o=e.next;t!==null?t.next=o:n.head=o,o!==null?o.prev=t:n.tail=t,e.attached=!1,e.prev=null,e.next=null}N(e)}function S(e){e.flags|=16;let n=e.deps;for(;n!==void 0;)n=q(n,e);let t=e.subs;for(;t!==void 0;){let r=t.nextSub;q(t,t.sub),t=r}let o=e.scope;o!==void 0&&(E(o),e.scope=void 0,e.fn=void 0)}function h(e,n){if(e instanceof p)throw e;let t=n;for(;t!==null;){let o=t.handler;if(o!==null){try{o(e)}catch(r){h(r,t.parent)}return}t=t.parent}A(e)}function l(){return f&&(d=v(I),f=!1),d}function a(e){let n=l();return d=e,f=!1,n}function pe(){let e=l();return I=e,f=!0,d=null,e}function xe(e){d=e,f=!1,I=null}function m(e){let n=l();n!==null&&(n.cells??=[]).push(e)}function X(e){let n=v(l());return e.scope=n,n}function z(e){$(e)}function J(e){e.flags|=16,e.fn=void 0;let n=l();n!==null&&n.cells.pop()}function c(e){return e===void 0?ie:e===!1?le:e}function ve(e){j++;try{return e()}finally{--j===0&&Y()}}function he(e){try{return K(e)}finally{}}function K(e){let n=u;u=void 0;try{return e()}finally{u=n}}function we(e,n){let t=new s(0,e,void 0,c(n?.equals));return t}function be(e,n){let t=new s(5,void 0,e,c(n?.equals));return m(t),e.name,t}function W(e){let n=new s(2,void 0,e,c(void 0));return e.name,m(n),X(n),R||z(n),n}var R=!1;function Ce(e){let n=R;return R=e,n}function ye(){return R}function ge(e){let n=W(e);n.deps===void 0&&J(n)}function me(e){l()===null&&void 0;let n=W(e);return()=>{S(n)}}function Te(e){let n=l();if(n===null){return}(n.disposals??=[]).push(e)}function ke(e){let n=v(l());let t=a(n);try{return e(()=>{E(n)})}finally{a(t)}}function Oe(e,n){let t=v(l());t.handler=n;let o=a(t);try{let r=e();return a(o),r}catch(r){a(o),h(r,t);return}}function Ee(e,n){let t=a(e);try{return n()}finally{a(t)}}var ee=Symbol("firsthand.ctx");function Se(e,n){let t=n??"context";return{id:Symbol(t),description:t,hasDefault:arguments.length>0,defaultValue:e,fallback:void 0}}function Re(e,n){let t=l();if(t===null){`${e.description}`;return}let o=n instanceof s?n:new s(0,n,void 0,c(void 0));Le(t)[e.id]=o}function De(e){let n=l(),t=n!==null?n.ctx:null,o=t!==null?t[e.id]:void 0;if(o!==void 0)return o;let r=e;if(!r.hasDefault)throw new w(r.description);return r.fallback??=new s(0,r.defaultValue,void 0,c(void 0))}function Le(e){let n=e.ctx;if(n!==null&&n[ee]===e)return n;let t=n!==null?Object.create(n):Object.create(null);return t[ee]=e,e.ctx=t,t}export{s as Cell,w as FirsthandContextError,p as FirsthandCycleError,x as FirsthandReadonlyError,ve as batch,ge as bind,Oe as catchError,be as computed,Se as createContext,W as createEffect,v as createOwner,ke as createRoot,pe as deferOwner,te as devEnterSetup,oe as devExitSetup,S as disposeCell,E as disposeOwner,me as effect,l as getOwner,h as handleError,ye as isRendering,Te as onCleanup,m as own,Re as provide,xe as restoreOwner,Ee as runWithOwner,a as setOwner,Ce as setRendering,ne as setStrictReactivity,we as signal,he as snapshot,K as untrack,De as useContext};
|
package/dist/types.d.ts
CHANGED
|
@@ -22,7 +22,9 @@ export type CellOptions<T> = {
|
|
|
22
22
|
equals?: ((a: T, b: T) => boolean) | false;
|
|
23
23
|
};
|
|
24
24
|
/** Deeply readonly view of a value. Used by `ReadonlyProps`. */
|
|
25
|
-
export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends Date | RegExp | Promise<unknown> ? T : T extends
|
|
25
|
+
export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends Date | RegExp | Promise<unknown> ? T : T extends {
|
|
26
|
+
readonly nodeType: number;
|
|
27
|
+
} ? T : T extends object ? {
|
|
26
28
|
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
27
29
|
} : T;
|
|
28
30
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,8CAA8C;AAC9C,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,0CAA0C;IAC1C,IAAI,IAAI,CAAC,CAAC;CACX,CAAC;AAEF,qDAAqD;AACrD,MAAM,WAAW,MAAM,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAChD,KAAK,EAAE,CAAC,CAAC;IACT,qDAAqD;IACrD,GAAG,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;CACxC;AAED,2DAA2D;AAC3D,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AAEjC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,KAAK,CAAC;CAC5C,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GACjE,CAAC,GACD,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAC9B,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAC9B,CAAC,SAAS,WAAW,CAAC,M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