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.auto.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
|
*/
|
|
@@ -189,10 +189,35 @@
|
|
|
189
189
|
* count.value++; // Triggers effect
|
|
190
190
|
* ```
|
|
191
191
|
*/
|
|
192
|
-
/**
|
|
193
|
-
* Current effect being tracked
|
|
194
|
-
*/
|
|
195
192
|
let currentEffect = null;
|
|
193
|
+
function track(source) {
|
|
194
|
+
if (!currentEffect)
|
|
195
|
+
return;
|
|
196
|
+
source.subscribers.add(currentEffect);
|
|
197
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
198
|
+
currentEffect.__versions?.set(source, source.version);
|
|
199
|
+
}
|
|
200
|
+
function dependenciesChanged(versions) {
|
|
201
|
+
return untrack(() => {
|
|
202
|
+
for (const [source, version] of versions) {
|
|
203
|
+
source.refresh?.();
|
|
204
|
+
if (source.version !== version)
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
211
|
+
function notifySubscribers(subscribers) {
|
|
212
|
+
for (const sub of Array.from(subscribers)) {
|
|
213
|
+
if (sub.__invalidate)
|
|
214
|
+
sub();
|
|
215
|
+
else if (isBatching)
|
|
216
|
+
batchedEffects.add(sub);
|
|
217
|
+
else
|
|
218
|
+
queueEffect(sub);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
196
221
|
// Simple counter for debug-friendly IDs
|
|
197
222
|
let signalIdCounter = 0;
|
|
198
223
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -230,6 +255,9 @@
|
|
|
230
255
|
}
|
|
231
256
|
});
|
|
232
257
|
isFlushingQueue = false;
|
|
258
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
259
|
+
if (effectQueue.size > 0)
|
|
260
|
+
queueMicrotask(flushEffectQueue);
|
|
233
261
|
}
|
|
234
262
|
/**
|
|
235
263
|
* Queue an effect for execution in next microtask
|
|
@@ -288,17 +316,14 @@
|
|
|
288
316
|
const debugId = ++signalIdCounter;
|
|
289
317
|
let value = initialValue;
|
|
290
318
|
const subscribers = new Set();
|
|
319
|
+
const source = { subscribers, version: 0 };
|
|
291
320
|
let warnedSubscribers = false;
|
|
292
321
|
const read = () => {
|
|
293
322
|
// Track dependency
|
|
294
323
|
if (currentEffect) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
299
|
-
if (currentEffect.__dependencies) {
|
|
300
|
-
currentEffect.__dependencies.add(subscribers);
|
|
301
|
-
}
|
|
324
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
325
|
+
track(source);
|
|
326
|
+
if (!wasSubscribed) {
|
|
302
327
|
if (DEBUG_VERBOSE()) {
|
|
303
328
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
304
329
|
}
|
|
@@ -317,18 +342,13 @@
|
|
|
317
342
|
// For objects/arrays, check if it's actually the same reference
|
|
318
343
|
// Deep equality is expensive, let user handle it
|
|
319
344
|
value = newValue;
|
|
345
|
+
source.version++;
|
|
320
346
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
321
347
|
notify();
|
|
322
348
|
};
|
|
323
349
|
const notify = () => {
|
|
324
350
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
325
|
-
|
|
326
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
// Always queue effects to prevent cascading updates
|
|
330
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
331
|
-
}
|
|
351
|
+
notifySubscribers(subscribers);
|
|
332
352
|
};
|
|
333
353
|
// Create callable signal (like Angular/SolidJS)
|
|
334
354
|
// Call without args = read, call with arg = write
|
|
@@ -363,8 +383,16 @@
|
|
|
363
383
|
},
|
|
364
384
|
subscribe: {
|
|
365
385
|
value: function (fn) {
|
|
366
|
-
|
|
367
|
-
|
|
386
|
+
let active = true;
|
|
387
|
+
const callback = () => { if (active)
|
|
388
|
+
untrack(fn); };
|
|
389
|
+
subscribers.add(callback);
|
|
390
|
+
return () => {
|
|
391
|
+
active = false;
|
|
392
|
+
subscribers.delete(callback);
|
|
393
|
+
effectQueue.delete(callback);
|
|
394
|
+
batchedEffects.delete(callback);
|
|
395
|
+
};
|
|
368
396
|
},
|
|
369
397
|
enumerable: true,
|
|
370
398
|
configurable: true
|
|
@@ -424,49 +452,60 @@
|
|
|
424
452
|
let value;
|
|
425
453
|
let isDirty = true;
|
|
426
454
|
let isFirstRun = true;
|
|
455
|
+
let computing = false;
|
|
427
456
|
const subscribers = new Set();
|
|
428
|
-
|
|
457
|
+
const dependencies = new Set();
|
|
458
|
+
const versions = new Map();
|
|
459
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
460
|
+
const invalidate = () => {
|
|
461
|
+
// A later batched write must also move already queued consumers into
|
|
462
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
463
|
+
if (isDirty && !isBatching)
|
|
464
|
+
return;
|
|
465
|
+
isDirty = true;
|
|
466
|
+
notifySubscribers(subscribers);
|
|
467
|
+
};
|
|
468
|
+
invalidate.__invalidate = true;
|
|
469
|
+
invalidate.__dependencies = dependencies;
|
|
470
|
+
invalidate.__versions = versions;
|
|
429
471
|
const compute = () => {
|
|
430
472
|
if (!isDirty && !isFirstRun)
|
|
431
473
|
return;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
value = newValue;
|
|
442
|
-
isFirstRun = false;
|
|
443
|
-
isDirty = false;
|
|
444
|
-
// Notify subscribers
|
|
445
|
-
if (!isBatching) {
|
|
446
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
450
|
-
}
|
|
451
|
-
}
|
|
474
|
+
if (computing)
|
|
475
|
+
throw new Error('[Computed] Circular dependency');
|
|
476
|
+
computing = true;
|
|
477
|
+
const previousEffect = currentEffect;
|
|
478
|
+
try {
|
|
479
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
480
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
481
|
+
isDirty = false;
|
|
482
|
+
return;
|
|
452
483
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
484
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
485
|
+
dependencies.clear();
|
|
486
|
+
versions.clear();
|
|
487
|
+
currentEffect = invalidate;
|
|
488
|
+
const nextValue = fn();
|
|
489
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
490
|
+
value = nextValue;
|
|
491
|
+
source.version++;
|
|
456
492
|
}
|
|
457
|
-
|
|
458
|
-
|
|
493
|
+
isFirstRun = false;
|
|
494
|
+
isDirty = false;
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
// Preserve error isolation and the last successful value.
|
|
498
|
+
console.error('[Computed] Error in computation:', error);
|
|
499
|
+
isDirty = false;
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
currentEffect = previousEffect;
|
|
503
|
+
computing = false;
|
|
504
|
+
}
|
|
459
505
|
};
|
|
460
506
|
const read = () => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
// Track dependency
|
|
464
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
465
|
-
subscribers.add(currentEffect);
|
|
466
|
-
if (currentEffect.__dependencies) {
|
|
467
|
-
currentEffect.__dependencies.add(subscribers);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
507
|
+
compute();
|
|
508
|
+
track(source);
|
|
470
509
|
return value;
|
|
471
510
|
};
|
|
472
511
|
// Create callable computed (read-only)
|
|
@@ -491,8 +530,14 @@
|
|
|
491
530
|
},
|
|
492
531
|
subscribe: {
|
|
493
532
|
value: function (fn) {
|
|
494
|
-
|
|
495
|
-
|
|
533
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
534
|
+
let first = true;
|
|
535
|
+
return effect(() => {
|
|
536
|
+
read();
|
|
537
|
+
if (!first)
|
|
538
|
+
untrack(fn);
|
|
539
|
+
first = false;
|
|
540
|
+
});
|
|
496
541
|
},
|
|
497
542
|
enumerable: true,
|
|
498
543
|
configurable: true
|
|
@@ -543,11 +588,15 @@
|
|
|
543
588
|
*/
|
|
544
589
|
function effect(fn) {
|
|
545
590
|
let cleanup;
|
|
546
|
-
|
|
591
|
+
const dependencies = new Set();
|
|
592
|
+
const versions = new Map();
|
|
547
593
|
let active = true;
|
|
594
|
+
let initialized = false;
|
|
548
595
|
const execute = () => {
|
|
549
596
|
if (!active)
|
|
550
597
|
return;
|
|
598
|
+
if (initialized && !dependenciesChanged(versions))
|
|
599
|
+
return;
|
|
551
600
|
// Prevent recursive execution - if already running, skip
|
|
552
601
|
if (runningEffects.has(execute)) {
|
|
553
602
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -562,10 +611,13 @@
|
|
|
562
611
|
});
|
|
563
612
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
564
613
|
dependencies.clear();
|
|
614
|
+
versions.clear();
|
|
565
615
|
// Clean up previous run
|
|
566
616
|
if (cleanup) {
|
|
617
|
+
const previousCleanup = cleanup;
|
|
618
|
+
cleanup = undefined;
|
|
567
619
|
try {
|
|
568
|
-
|
|
620
|
+
untrack(previousCleanup);
|
|
569
621
|
}
|
|
570
622
|
catch (error) {
|
|
571
623
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -576,6 +628,7 @@
|
|
|
576
628
|
currentEffect = execute;
|
|
577
629
|
// Store dependencies for cleanup
|
|
578
630
|
execute.__dependencies = dependencies;
|
|
631
|
+
execute.__versions = versions;
|
|
579
632
|
try {
|
|
580
633
|
const nextCleanup = fn();
|
|
581
634
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -585,6 +638,7 @@
|
|
|
585
638
|
// Don't throw - allow other effects to continue
|
|
586
639
|
}
|
|
587
640
|
finally {
|
|
641
|
+
initialized = true;
|
|
588
642
|
currentEffect = prevEffect;
|
|
589
643
|
effectDepth--;
|
|
590
644
|
runningEffects.delete(execute);
|
|
@@ -601,14 +655,17 @@
|
|
|
601
655
|
if (!active)
|
|
602
656
|
return;
|
|
603
657
|
active = false;
|
|
658
|
+
effectQueue.delete(execute);
|
|
659
|
+
batchedEffects.delete(execute);
|
|
604
660
|
// Remove from all dependencies
|
|
605
661
|
dependencies.forEach(depSet => {
|
|
606
662
|
depSet.delete(execute);
|
|
607
663
|
});
|
|
608
664
|
dependencies.clear();
|
|
665
|
+
versions.clear();
|
|
609
666
|
if (cleanup) {
|
|
610
667
|
try {
|
|
611
|
-
cleanup
|
|
668
|
+
untrack(cleanup);
|
|
612
669
|
}
|
|
613
670
|
catch (error) {
|
|
614
671
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -668,6 +725,8 @@
|
|
|
668
725
|
const effects = Array.from(batchedEffects);
|
|
669
726
|
batchedEffects.clear();
|
|
670
727
|
effects.forEach(effect => {
|
|
728
|
+
// This batch also settles any earlier queued write to this observer.
|
|
729
|
+
effectQueue.delete(effect);
|
|
671
730
|
try {
|
|
672
731
|
effect();
|
|
673
732
|
}
|
|
@@ -8712,7 +8771,7 @@
|
|
|
8712
8771
|
portalCreate,
|
|
8713
8772
|
portalDestroy,
|
|
8714
8773
|
setCspNonce,
|
|
8715
|
-
version: '0.4.
|
|
8774
|
+
version: '0.4.1'
|
|
8716
8775
|
};
|
|
8717
8776
|
|
|
8718
8777
|
const standardExpressionRuntime = {
|