gyosjs 0.4.0 → 0.4.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/README.md +3 -1
- package/dist/gyos.auto.esm.js +120 -61
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +120 -61
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +120 -61
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +120 -61
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +120 -61
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +120 -61
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +120 -61
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +120 -61
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/reactivity/signal.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/gyos.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.4.
|
|
2
|
+
* GyosJS v0.4.1
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -229,10 +229,35 @@ function hasStructuralParent(el) {
|
|
|
229
229
|
* count.value++; // Triggers effect
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
|
-
/**
|
|
233
|
-
* Current effect being tracked
|
|
234
|
-
*/
|
|
235
232
|
let currentEffect = null;
|
|
233
|
+
function track(source) {
|
|
234
|
+
if (!currentEffect)
|
|
235
|
+
return;
|
|
236
|
+
source.subscribers.add(currentEffect);
|
|
237
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
238
|
+
currentEffect.__versions?.set(source, source.version);
|
|
239
|
+
}
|
|
240
|
+
function dependenciesChanged(versions) {
|
|
241
|
+
return untrack(() => {
|
|
242
|
+
for (const [source, version] of versions) {
|
|
243
|
+
source.refresh?.();
|
|
244
|
+
if (source.version !== version)
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
251
|
+
function notifySubscribers(subscribers) {
|
|
252
|
+
for (const sub of Array.from(subscribers)) {
|
|
253
|
+
if (sub.__invalidate)
|
|
254
|
+
sub();
|
|
255
|
+
else if (isBatching)
|
|
256
|
+
batchedEffects.add(sub);
|
|
257
|
+
else
|
|
258
|
+
queueEffect(sub);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
236
261
|
// Simple counter for debug-friendly IDs
|
|
237
262
|
let signalIdCounter = 0;
|
|
238
263
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -270,6 +295,9 @@ function flushEffectQueue() {
|
|
|
270
295
|
}
|
|
271
296
|
});
|
|
272
297
|
isFlushingQueue = false;
|
|
298
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
299
|
+
if (effectQueue.size > 0)
|
|
300
|
+
queueMicrotask(flushEffectQueue);
|
|
273
301
|
}
|
|
274
302
|
/**
|
|
275
303
|
* Queue an effect for execution in next microtask
|
|
@@ -328,17 +356,14 @@ function signal(initialValue, debugOrOptions) {
|
|
|
328
356
|
const debugId = ++signalIdCounter;
|
|
329
357
|
let value = initialValue;
|
|
330
358
|
const subscribers = new Set();
|
|
359
|
+
const source = { subscribers, version: 0 };
|
|
331
360
|
let warnedSubscribers = false;
|
|
332
361
|
const read = () => {
|
|
333
362
|
// Track dependency
|
|
334
363
|
if (currentEffect) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
339
|
-
if (currentEffect.__dependencies) {
|
|
340
|
-
currentEffect.__dependencies.add(subscribers);
|
|
341
|
-
}
|
|
364
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
365
|
+
track(source);
|
|
366
|
+
if (!wasSubscribed) {
|
|
342
367
|
if (DEBUG_VERBOSE()) {
|
|
343
368
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
344
369
|
}
|
|
@@ -357,18 +382,13 @@ function signal(initialValue, debugOrOptions) {
|
|
|
357
382
|
// For objects/arrays, check if it's actually the same reference
|
|
358
383
|
// Deep equality is expensive, let user handle it
|
|
359
384
|
value = newValue;
|
|
385
|
+
source.version++;
|
|
360
386
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
361
387
|
notify();
|
|
362
388
|
};
|
|
363
389
|
const notify = () => {
|
|
364
390
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
365
|
-
|
|
366
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
// Always queue effects to prevent cascading updates
|
|
370
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
371
|
-
}
|
|
391
|
+
notifySubscribers(subscribers);
|
|
372
392
|
};
|
|
373
393
|
// Create callable signal (like Angular/SolidJS)
|
|
374
394
|
// Call without args = read, call with arg = write
|
|
@@ -403,8 +423,16 @@ function signal(initialValue, debugOrOptions) {
|
|
|
403
423
|
},
|
|
404
424
|
subscribe: {
|
|
405
425
|
value: function (fn) {
|
|
406
|
-
|
|
407
|
-
|
|
426
|
+
let active = true;
|
|
427
|
+
const callback = () => { if (active)
|
|
428
|
+
untrack(fn); };
|
|
429
|
+
subscribers.add(callback);
|
|
430
|
+
return () => {
|
|
431
|
+
active = false;
|
|
432
|
+
subscribers.delete(callback);
|
|
433
|
+
effectQueue.delete(callback);
|
|
434
|
+
batchedEffects.delete(callback);
|
|
435
|
+
};
|
|
408
436
|
},
|
|
409
437
|
enumerable: true,
|
|
410
438
|
configurable: true
|
|
@@ -464,49 +492,60 @@ function computed(fn) {
|
|
|
464
492
|
let value;
|
|
465
493
|
let isDirty = true;
|
|
466
494
|
let isFirstRun = true;
|
|
495
|
+
let computing = false;
|
|
467
496
|
const subscribers = new Set();
|
|
468
|
-
|
|
497
|
+
const dependencies = new Set();
|
|
498
|
+
const versions = new Map();
|
|
499
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
500
|
+
const invalidate = () => {
|
|
501
|
+
// A later batched write must also move already queued consumers into
|
|
502
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
503
|
+
if (isDirty && !isBatching)
|
|
504
|
+
return;
|
|
505
|
+
isDirty = true;
|
|
506
|
+
notifySubscribers(subscribers);
|
|
507
|
+
};
|
|
508
|
+
invalidate.__invalidate = true;
|
|
509
|
+
invalidate.__dependencies = dependencies;
|
|
510
|
+
invalidate.__versions = versions;
|
|
469
511
|
const compute = () => {
|
|
470
512
|
if (!isDirty && !isFirstRun)
|
|
471
513
|
return;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
value = newValue;
|
|
482
|
-
isFirstRun = false;
|
|
483
|
-
isDirty = false;
|
|
484
|
-
// Notify subscribers
|
|
485
|
-
if (!isBatching) {
|
|
486
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
514
|
+
if (computing)
|
|
515
|
+
throw new Error('[Computed] Circular dependency');
|
|
516
|
+
computing = true;
|
|
517
|
+
const previousEffect = currentEffect;
|
|
518
|
+
try {
|
|
519
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
520
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
521
|
+
isDirty = false;
|
|
522
|
+
return;
|
|
492
523
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
524
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
525
|
+
dependencies.clear();
|
|
526
|
+
versions.clear();
|
|
527
|
+
currentEffect = invalidate;
|
|
528
|
+
const nextValue = fn();
|
|
529
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
530
|
+
value = nextValue;
|
|
531
|
+
source.version++;
|
|
496
532
|
}
|
|
497
|
-
|
|
498
|
-
|
|
533
|
+
isFirstRun = false;
|
|
534
|
+
isDirty = false;
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
// Preserve error isolation and the last successful value.
|
|
538
|
+
console.error('[Computed] Error in computation:', error);
|
|
539
|
+
isDirty = false;
|
|
540
|
+
}
|
|
541
|
+
finally {
|
|
542
|
+
currentEffect = previousEffect;
|
|
543
|
+
computing = false;
|
|
544
|
+
}
|
|
499
545
|
};
|
|
500
546
|
const read = () => {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
// Track dependency
|
|
504
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
505
|
-
subscribers.add(currentEffect);
|
|
506
|
-
if (currentEffect.__dependencies) {
|
|
507
|
-
currentEffect.__dependencies.add(subscribers);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
547
|
+
compute();
|
|
548
|
+
track(source);
|
|
510
549
|
return value;
|
|
511
550
|
};
|
|
512
551
|
// Create callable computed (read-only)
|
|
@@ -531,8 +570,14 @@ function computed(fn) {
|
|
|
531
570
|
},
|
|
532
571
|
subscribe: {
|
|
533
572
|
value: function (fn) {
|
|
534
|
-
|
|
535
|
-
|
|
573
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
574
|
+
let first = true;
|
|
575
|
+
return effect(() => {
|
|
576
|
+
read();
|
|
577
|
+
if (!first)
|
|
578
|
+
untrack(fn);
|
|
579
|
+
first = false;
|
|
580
|
+
});
|
|
536
581
|
},
|
|
537
582
|
enumerable: true,
|
|
538
583
|
configurable: true
|
|
@@ -583,11 +628,15 @@ function computed(fn) {
|
|
|
583
628
|
*/
|
|
584
629
|
function effect(fn) {
|
|
585
630
|
let cleanup;
|
|
586
|
-
|
|
631
|
+
const dependencies = new Set();
|
|
632
|
+
const versions = new Map();
|
|
587
633
|
let active = true;
|
|
634
|
+
let initialized = false;
|
|
588
635
|
const execute = () => {
|
|
589
636
|
if (!active)
|
|
590
637
|
return;
|
|
638
|
+
if (initialized && !dependenciesChanged(versions))
|
|
639
|
+
return;
|
|
591
640
|
// Prevent recursive execution - if already running, skip
|
|
592
641
|
if (runningEffects.has(execute)) {
|
|
593
642
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -602,10 +651,13 @@ function effect(fn) {
|
|
|
602
651
|
});
|
|
603
652
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
604
653
|
dependencies.clear();
|
|
654
|
+
versions.clear();
|
|
605
655
|
// Clean up previous run
|
|
606
656
|
if (cleanup) {
|
|
657
|
+
const previousCleanup = cleanup;
|
|
658
|
+
cleanup = undefined;
|
|
607
659
|
try {
|
|
608
|
-
|
|
660
|
+
untrack(previousCleanup);
|
|
609
661
|
}
|
|
610
662
|
catch (error) {
|
|
611
663
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -616,6 +668,7 @@ function effect(fn) {
|
|
|
616
668
|
currentEffect = execute;
|
|
617
669
|
// Store dependencies for cleanup
|
|
618
670
|
execute.__dependencies = dependencies;
|
|
671
|
+
execute.__versions = versions;
|
|
619
672
|
try {
|
|
620
673
|
const nextCleanup = fn();
|
|
621
674
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -625,6 +678,7 @@ function effect(fn) {
|
|
|
625
678
|
// Don't throw - allow other effects to continue
|
|
626
679
|
}
|
|
627
680
|
finally {
|
|
681
|
+
initialized = true;
|
|
628
682
|
currentEffect = prevEffect;
|
|
629
683
|
effectDepth--;
|
|
630
684
|
runningEffects.delete(execute);
|
|
@@ -641,14 +695,17 @@ function effect(fn) {
|
|
|
641
695
|
if (!active)
|
|
642
696
|
return;
|
|
643
697
|
active = false;
|
|
698
|
+
effectQueue.delete(execute);
|
|
699
|
+
batchedEffects.delete(execute);
|
|
644
700
|
// Remove from all dependencies
|
|
645
701
|
dependencies.forEach(depSet => {
|
|
646
702
|
depSet.delete(execute);
|
|
647
703
|
});
|
|
648
704
|
dependencies.clear();
|
|
705
|
+
versions.clear();
|
|
649
706
|
if (cleanup) {
|
|
650
707
|
try {
|
|
651
|
-
cleanup
|
|
708
|
+
untrack(cleanup);
|
|
652
709
|
}
|
|
653
710
|
catch (error) {
|
|
654
711
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -708,6 +765,8 @@ function batch(fn) {
|
|
|
708
765
|
const effects = Array.from(batchedEffects);
|
|
709
766
|
batchedEffects.clear();
|
|
710
767
|
effects.forEach(effect => {
|
|
768
|
+
// This batch also settles any earlier queued write to this observer.
|
|
769
|
+
effectQueue.delete(effect);
|
|
711
770
|
try {
|
|
712
771
|
effect();
|
|
713
772
|
}
|
|
@@ -8738,7 +8797,7 @@ const Gyos = {
|
|
|
8738
8797
|
portalCreate,
|
|
8739
8798
|
portalDestroy,
|
|
8740
8799
|
setCspNonce,
|
|
8741
|
-
version: '0.4.
|
|
8800
|
+
version: '0.4.1'
|
|
8742
8801
|
};
|
|
8743
8802
|
|
|
8744
8803
|
setExpressionRuntime(standardExpressionRuntime);
|