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.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
|
*/
|
|
@@ -235,10 +235,35 @@
|
|
|
235
235
|
* count.value++; // Triggers effect
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
|
-
/**
|
|
239
|
-
* Current effect being tracked
|
|
240
|
-
*/
|
|
241
238
|
let currentEffect = null;
|
|
239
|
+
function track(source) {
|
|
240
|
+
if (!currentEffect)
|
|
241
|
+
return;
|
|
242
|
+
source.subscribers.add(currentEffect);
|
|
243
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
244
|
+
currentEffect.__versions?.set(source, source.version);
|
|
245
|
+
}
|
|
246
|
+
function dependenciesChanged(versions) {
|
|
247
|
+
return untrack(() => {
|
|
248
|
+
for (const [source, version] of versions) {
|
|
249
|
+
source.refresh?.();
|
|
250
|
+
if (source.version !== version)
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
257
|
+
function notifySubscribers(subscribers) {
|
|
258
|
+
for (const sub of Array.from(subscribers)) {
|
|
259
|
+
if (sub.__invalidate)
|
|
260
|
+
sub();
|
|
261
|
+
else if (isBatching)
|
|
262
|
+
batchedEffects.add(sub);
|
|
263
|
+
else
|
|
264
|
+
queueEffect(sub);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
242
267
|
// Simple counter for debug-friendly IDs
|
|
243
268
|
let signalIdCounter = 0;
|
|
244
269
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -276,6 +301,9 @@
|
|
|
276
301
|
}
|
|
277
302
|
});
|
|
278
303
|
isFlushingQueue = false;
|
|
304
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
305
|
+
if (effectQueue.size > 0)
|
|
306
|
+
queueMicrotask(flushEffectQueue);
|
|
279
307
|
}
|
|
280
308
|
/**
|
|
281
309
|
* Queue an effect for execution in next microtask
|
|
@@ -334,17 +362,14 @@
|
|
|
334
362
|
const debugId = ++signalIdCounter;
|
|
335
363
|
let value = initialValue;
|
|
336
364
|
const subscribers = new Set();
|
|
365
|
+
const source = { subscribers, version: 0 };
|
|
337
366
|
let warnedSubscribers = false;
|
|
338
367
|
const read = () => {
|
|
339
368
|
// Track dependency
|
|
340
369
|
if (currentEffect) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
345
|
-
if (currentEffect.__dependencies) {
|
|
346
|
-
currentEffect.__dependencies.add(subscribers);
|
|
347
|
-
}
|
|
370
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
371
|
+
track(source);
|
|
372
|
+
if (!wasSubscribed) {
|
|
348
373
|
if (DEBUG_VERBOSE()) {
|
|
349
374
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
350
375
|
}
|
|
@@ -363,18 +388,13 @@
|
|
|
363
388
|
// For objects/arrays, check if it's actually the same reference
|
|
364
389
|
// Deep equality is expensive, let user handle it
|
|
365
390
|
value = newValue;
|
|
391
|
+
source.version++;
|
|
366
392
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
367
393
|
notify();
|
|
368
394
|
};
|
|
369
395
|
const notify = () => {
|
|
370
396
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
371
|
-
|
|
372
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
// Always queue effects to prevent cascading updates
|
|
376
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
377
|
-
}
|
|
397
|
+
notifySubscribers(subscribers);
|
|
378
398
|
};
|
|
379
399
|
// Create callable signal (like Angular/SolidJS)
|
|
380
400
|
// Call without args = read, call with arg = write
|
|
@@ -409,8 +429,16 @@
|
|
|
409
429
|
},
|
|
410
430
|
subscribe: {
|
|
411
431
|
value: function (fn) {
|
|
412
|
-
|
|
413
|
-
|
|
432
|
+
let active = true;
|
|
433
|
+
const callback = () => { if (active)
|
|
434
|
+
untrack(fn); };
|
|
435
|
+
subscribers.add(callback);
|
|
436
|
+
return () => {
|
|
437
|
+
active = false;
|
|
438
|
+
subscribers.delete(callback);
|
|
439
|
+
effectQueue.delete(callback);
|
|
440
|
+
batchedEffects.delete(callback);
|
|
441
|
+
};
|
|
414
442
|
},
|
|
415
443
|
enumerable: true,
|
|
416
444
|
configurable: true
|
|
@@ -470,49 +498,60 @@
|
|
|
470
498
|
let value;
|
|
471
499
|
let isDirty = true;
|
|
472
500
|
let isFirstRun = true;
|
|
501
|
+
let computing = false;
|
|
473
502
|
const subscribers = new Set();
|
|
474
|
-
|
|
503
|
+
const dependencies = new Set();
|
|
504
|
+
const versions = new Map();
|
|
505
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
506
|
+
const invalidate = () => {
|
|
507
|
+
// A later batched write must also move already queued consumers into
|
|
508
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
509
|
+
if (isDirty && !isBatching)
|
|
510
|
+
return;
|
|
511
|
+
isDirty = true;
|
|
512
|
+
notifySubscribers(subscribers);
|
|
513
|
+
};
|
|
514
|
+
invalidate.__invalidate = true;
|
|
515
|
+
invalidate.__dependencies = dependencies;
|
|
516
|
+
invalidate.__versions = versions;
|
|
475
517
|
const compute = () => {
|
|
476
518
|
if (!isDirty && !isFirstRun)
|
|
477
519
|
return;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
value = newValue;
|
|
488
|
-
isFirstRun = false;
|
|
489
|
-
isDirty = false;
|
|
490
|
-
// Notify subscribers
|
|
491
|
-
if (!isBatching) {
|
|
492
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
493
|
-
}
|
|
494
|
-
else {
|
|
495
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
496
|
-
}
|
|
497
|
-
}
|
|
520
|
+
if (computing)
|
|
521
|
+
throw new Error('[Computed] Circular dependency');
|
|
522
|
+
computing = true;
|
|
523
|
+
const previousEffect = currentEffect;
|
|
524
|
+
try {
|
|
525
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
526
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
527
|
+
isDirty = false;
|
|
528
|
+
return;
|
|
498
529
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
530
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
531
|
+
dependencies.clear();
|
|
532
|
+
versions.clear();
|
|
533
|
+
currentEffect = invalidate;
|
|
534
|
+
const nextValue = fn();
|
|
535
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
536
|
+
value = nextValue;
|
|
537
|
+
source.version++;
|
|
502
538
|
}
|
|
503
|
-
|
|
504
|
-
|
|
539
|
+
isFirstRun = false;
|
|
540
|
+
isDirty = false;
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
// Preserve error isolation and the last successful value.
|
|
544
|
+
console.error('[Computed] Error in computation:', error);
|
|
545
|
+
isDirty = false;
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
currentEffect = previousEffect;
|
|
549
|
+
computing = false;
|
|
550
|
+
}
|
|
505
551
|
};
|
|
506
552
|
const read = () => {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
// Track dependency
|
|
510
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
511
|
-
subscribers.add(currentEffect);
|
|
512
|
-
if (currentEffect.__dependencies) {
|
|
513
|
-
currentEffect.__dependencies.add(subscribers);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
553
|
+
compute();
|
|
554
|
+
track(source);
|
|
516
555
|
return value;
|
|
517
556
|
};
|
|
518
557
|
// Create callable computed (read-only)
|
|
@@ -537,8 +576,14 @@
|
|
|
537
576
|
},
|
|
538
577
|
subscribe: {
|
|
539
578
|
value: function (fn) {
|
|
540
|
-
|
|
541
|
-
|
|
579
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
580
|
+
let first = true;
|
|
581
|
+
return effect(() => {
|
|
582
|
+
read();
|
|
583
|
+
if (!first)
|
|
584
|
+
untrack(fn);
|
|
585
|
+
first = false;
|
|
586
|
+
});
|
|
542
587
|
},
|
|
543
588
|
enumerable: true,
|
|
544
589
|
configurable: true
|
|
@@ -589,11 +634,15 @@
|
|
|
589
634
|
*/
|
|
590
635
|
function effect(fn) {
|
|
591
636
|
let cleanup;
|
|
592
|
-
|
|
637
|
+
const dependencies = new Set();
|
|
638
|
+
const versions = new Map();
|
|
593
639
|
let active = true;
|
|
640
|
+
let initialized = false;
|
|
594
641
|
const execute = () => {
|
|
595
642
|
if (!active)
|
|
596
643
|
return;
|
|
644
|
+
if (initialized && !dependenciesChanged(versions))
|
|
645
|
+
return;
|
|
597
646
|
// Prevent recursive execution - if already running, skip
|
|
598
647
|
if (runningEffects.has(execute)) {
|
|
599
648
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -608,10 +657,13 @@
|
|
|
608
657
|
});
|
|
609
658
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
610
659
|
dependencies.clear();
|
|
660
|
+
versions.clear();
|
|
611
661
|
// Clean up previous run
|
|
612
662
|
if (cleanup) {
|
|
663
|
+
const previousCleanup = cleanup;
|
|
664
|
+
cleanup = undefined;
|
|
613
665
|
try {
|
|
614
|
-
|
|
666
|
+
untrack(previousCleanup);
|
|
615
667
|
}
|
|
616
668
|
catch (error) {
|
|
617
669
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -622,6 +674,7 @@
|
|
|
622
674
|
currentEffect = execute;
|
|
623
675
|
// Store dependencies for cleanup
|
|
624
676
|
execute.__dependencies = dependencies;
|
|
677
|
+
execute.__versions = versions;
|
|
625
678
|
try {
|
|
626
679
|
const nextCleanup = fn();
|
|
627
680
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -631,6 +684,7 @@
|
|
|
631
684
|
// Don't throw - allow other effects to continue
|
|
632
685
|
}
|
|
633
686
|
finally {
|
|
687
|
+
initialized = true;
|
|
634
688
|
currentEffect = prevEffect;
|
|
635
689
|
effectDepth--;
|
|
636
690
|
runningEffects.delete(execute);
|
|
@@ -647,14 +701,17 @@
|
|
|
647
701
|
if (!active)
|
|
648
702
|
return;
|
|
649
703
|
active = false;
|
|
704
|
+
effectQueue.delete(execute);
|
|
705
|
+
batchedEffects.delete(execute);
|
|
650
706
|
// Remove from all dependencies
|
|
651
707
|
dependencies.forEach(depSet => {
|
|
652
708
|
depSet.delete(execute);
|
|
653
709
|
});
|
|
654
710
|
dependencies.clear();
|
|
711
|
+
versions.clear();
|
|
655
712
|
if (cleanup) {
|
|
656
713
|
try {
|
|
657
|
-
cleanup
|
|
714
|
+
untrack(cleanup);
|
|
658
715
|
}
|
|
659
716
|
catch (error) {
|
|
660
717
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -714,6 +771,8 @@
|
|
|
714
771
|
const effects = Array.from(batchedEffects);
|
|
715
772
|
batchedEffects.clear();
|
|
716
773
|
effects.forEach(effect => {
|
|
774
|
+
// This batch also settles any earlier queued write to this observer.
|
|
775
|
+
effectQueue.delete(effect);
|
|
717
776
|
try {
|
|
718
777
|
effect();
|
|
719
778
|
}
|
|
@@ -8744,7 +8803,7 @@
|
|
|
8744
8803
|
portalCreate,
|
|
8745
8804
|
portalDestroy,
|
|
8746
8805
|
setCspNonce,
|
|
8747
|
-
version: '0.4.
|
|
8806
|
+
version: '0.4.1'
|
|
8748
8807
|
};
|
|
8749
8808
|
|
|
8750
8809
|
setExpressionRuntime(standardExpressionRuntime);
|