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.csp.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
|
*/
|
|
@@ -6852,10 +6852,35 @@
|
|
|
6852
6852
|
* count.value++; // Triggers effect
|
|
6853
6853
|
* ```
|
|
6854
6854
|
*/
|
|
6855
|
-
/**
|
|
6856
|
-
* Current effect being tracked
|
|
6857
|
-
*/
|
|
6858
6855
|
let currentEffect = null;
|
|
6856
|
+
function track(source) {
|
|
6857
|
+
if (!currentEffect)
|
|
6858
|
+
return;
|
|
6859
|
+
source.subscribers.add(currentEffect);
|
|
6860
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
6861
|
+
currentEffect.__versions?.set(source, source.version);
|
|
6862
|
+
}
|
|
6863
|
+
function dependenciesChanged(versions) {
|
|
6864
|
+
return untrack(() => {
|
|
6865
|
+
for (const [source, version] of versions) {
|
|
6866
|
+
source.refresh?.();
|
|
6867
|
+
if (source.version !== version)
|
|
6868
|
+
return true;
|
|
6869
|
+
}
|
|
6870
|
+
return false;
|
|
6871
|
+
});
|
|
6872
|
+
}
|
|
6873
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
6874
|
+
function notifySubscribers(subscribers) {
|
|
6875
|
+
for (const sub of Array.from(subscribers)) {
|
|
6876
|
+
if (sub.__invalidate)
|
|
6877
|
+
sub();
|
|
6878
|
+
else if (isBatching)
|
|
6879
|
+
batchedEffects.add(sub);
|
|
6880
|
+
else
|
|
6881
|
+
queueEffect(sub);
|
|
6882
|
+
}
|
|
6883
|
+
}
|
|
6859
6884
|
// Simple counter for debug-friendly IDs
|
|
6860
6885
|
let signalIdCounter = 0;
|
|
6861
6886
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -6893,6 +6918,9 @@
|
|
|
6893
6918
|
}
|
|
6894
6919
|
});
|
|
6895
6920
|
isFlushingQueue = false;
|
|
6921
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
6922
|
+
if (effectQueue.size > 0)
|
|
6923
|
+
queueMicrotask(flushEffectQueue);
|
|
6896
6924
|
}
|
|
6897
6925
|
/**
|
|
6898
6926
|
* Queue an effect for execution in next microtask
|
|
@@ -6951,17 +6979,14 @@
|
|
|
6951
6979
|
const debugId = ++signalIdCounter;
|
|
6952
6980
|
let value = initialValue;
|
|
6953
6981
|
const subscribers = new Set();
|
|
6982
|
+
const source = { subscribers, version: 0 };
|
|
6954
6983
|
let warnedSubscribers = false;
|
|
6955
6984
|
const read = () => {
|
|
6956
6985
|
// Track dependency
|
|
6957
6986
|
if (currentEffect) {
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
6962
|
-
if (currentEffect.__dependencies) {
|
|
6963
|
-
currentEffect.__dependencies.add(subscribers);
|
|
6964
|
-
}
|
|
6987
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
6988
|
+
track(source);
|
|
6989
|
+
if (!wasSubscribed) {
|
|
6965
6990
|
if (DEBUG_VERBOSE()) {
|
|
6966
6991
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
6967
6992
|
}
|
|
@@ -6980,18 +7005,13 @@
|
|
|
6980
7005
|
// For objects/arrays, check if it's actually the same reference
|
|
6981
7006
|
// Deep equality is expensive, let user handle it
|
|
6982
7007
|
value = newValue;
|
|
7008
|
+
source.version++;
|
|
6983
7009
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
6984
7010
|
notify();
|
|
6985
7011
|
};
|
|
6986
7012
|
const notify = () => {
|
|
6987
7013
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
6988
|
-
|
|
6989
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
6990
|
-
}
|
|
6991
|
-
else {
|
|
6992
|
-
// Always queue effects to prevent cascading updates
|
|
6993
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
6994
|
-
}
|
|
7014
|
+
notifySubscribers(subscribers);
|
|
6995
7015
|
};
|
|
6996
7016
|
// Create callable signal (like Angular/SolidJS)
|
|
6997
7017
|
// Call without args = read, call with arg = write
|
|
@@ -7026,8 +7046,16 @@
|
|
|
7026
7046
|
},
|
|
7027
7047
|
subscribe: {
|
|
7028
7048
|
value: function (fn) {
|
|
7029
|
-
|
|
7030
|
-
|
|
7049
|
+
let active = true;
|
|
7050
|
+
const callback = () => { if (active)
|
|
7051
|
+
untrack(fn); };
|
|
7052
|
+
subscribers.add(callback);
|
|
7053
|
+
return () => {
|
|
7054
|
+
active = false;
|
|
7055
|
+
subscribers.delete(callback);
|
|
7056
|
+
effectQueue.delete(callback);
|
|
7057
|
+
batchedEffects.delete(callback);
|
|
7058
|
+
};
|
|
7031
7059
|
},
|
|
7032
7060
|
enumerable: true,
|
|
7033
7061
|
configurable: true
|
|
@@ -7087,49 +7115,60 @@
|
|
|
7087
7115
|
let value;
|
|
7088
7116
|
let isDirty = true;
|
|
7089
7117
|
let isFirstRun = true;
|
|
7118
|
+
let computing = false;
|
|
7090
7119
|
const subscribers = new Set();
|
|
7091
|
-
|
|
7120
|
+
const dependencies = new Set();
|
|
7121
|
+
const versions = new Map();
|
|
7122
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
7123
|
+
const invalidate = () => {
|
|
7124
|
+
// A later batched write must also move already queued consumers into
|
|
7125
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
7126
|
+
if (isDirty && !isBatching)
|
|
7127
|
+
return;
|
|
7128
|
+
isDirty = true;
|
|
7129
|
+
notifySubscribers(subscribers);
|
|
7130
|
+
};
|
|
7131
|
+
invalidate.__invalidate = true;
|
|
7132
|
+
invalidate.__dependencies = dependencies;
|
|
7133
|
+
invalidate.__versions = versions;
|
|
7092
7134
|
const compute = () => {
|
|
7093
7135
|
if (!isDirty && !isFirstRun)
|
|
7094
7136
|
return;
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
value = newValue;
|
|
7105
|
-
isFirstRun = false;
|
|
7106
|
-
isDirty = false;
|
|
7107
|
-
// Notify subscribers
|
|
7108
|
-
if (!isBatching) {
|
|
7109
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
7110
|
-
}
|
|
7111
|
-
else {
|
|
7112
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
7113
|
-
}
|
|
7114
|
-
}
|
|
7137
|
+
if (computing)
|
|
7138
|
+
throw new Error('[Computed] Circular dependency');
|
|
7139
|
+
computing = true;
|
|
7140
|
+
const previousEffect = currentEffect;
|
|
7141
|
+
try {
|
|
7142
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
7143
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
7144
|
+
isDirty = false;
|
|
7145
|
+
return;
|
|
7115
7146
|
}
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7147
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
7148
|
+
dependencies.clear();
|
|
7149
|
+
versions.clear();
|
|
7150
|
+
currentEffect = invalidate;
|
|
7151
|
+
const nextValue = fn();
|
|
7152
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
7153
|
+
value = nextValue;
|
|
7154
|
+
source.version++;
|
|
7119
7155
|
}
|
|
7120
|
-
|
|
7121
|
-
|
|
7156
|
+
isFirstRun = false;
|
|
7157
|
+
isDirty = false;
|
|
7158
|
+
}
|
|
7159
|
+
catch (error) {
|
|
7160
|
+
// Preserve error isolation and the last successful value.
|
|
7161
|
+
console.error('[Computed] Error in computation:', error);
|
|
7162
|
+
isDirty = false;
|
|
7163
|
+
}
|
|
7164
|
+
finally {
|
|
7165
|
+
currentEffect = previousEffect;
|
|
7166
|
+
computing = false;
|
|
7167
|
+
}
|
|
7122
7168
|
};
|
|
7123
7169
|
const read = () => {
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
// Track dependency
|
|
7127
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
7128
|
-
subscribers.add(currentEffect);
|
|
7129
|
-
if (currentEffect.__dependencies) {
|
|
7130
|
-
currentEffect.__dependencies.add(subscribers);
|
|
7131
|
-
}
|
|
7132
|
-
}
|
|
7170
|
+
compute();
|
|
7171
|
+
track(source);
|
|
7133
7172
|
return value;
|
|
7134
7173
|
};
|
|
7135
7174
|
// Create callable computed (read-only)
|
|
@@ -7154,8 +7193,14 @@
|
|
|
7154
7193
|
},
|
|
7155
7194
|
subscribe: {
|
|
7156
7195
|
value: function (fn) {
|
|
7157
|
-
|
|
7158
|
-
|
|
7196
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
7197
|
+
let first = true;
|
|
7198
|
+
return effect(() => {
|
|
7199
|
+
read();
|
|
7200
|
+
if (!first)
|
|
7201
|
+
untrack(fn);
|
|
7202
|
+
first = false;
|
|
7203
|
+
});
|
|
7159
7204
|
},
|
|
7160
7205
|
enumerable: true,
|
|
7161
7206
|
configurable: true
|
|
@@ -7206,11 +7251,15 @@
|
|
|
7206
7251
|
*/
|
|
7207
7252
|
function effect(fn) {
|
|
7208
7253
|
let cleanup;
|
|
7209
|
-
|
|
7254
|
+
const dependencies = new Set();
|
|
7255
|
+
const versions = new Map();
|
|
7210
7256
|
let active = true;
|
|
7257
|
+
let initialized = false;
|
|
7211
7258
|
const execute = () => {
|
|
7212
7259
|
if (!active)
|
|
7213
7260
|
return;
|
|
7261
|
+
if (initialized && !dependenciesChanged(versions))
|
|
7262
|
+
return;
|
|
7214
7263
|
// Prevent recursive execution - if already running, skip
|
|
7215
7264
|
if (runningEffects.has(execute)) {
|
|
7216
7265
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -7225,10 +7274,13 @@
|
|
|
7225
7274
|
});
|
|
7226
7275
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
7227
7276
|
dependencies.clear();
|
|
7277
|
+
versions.clear();
|
|
7228
7278
|
// Clean up previous run
|
|
7229
7279
|
if (cleanup) {
|
|
7280
|
+
const previousCleanup = cleanup;
|
|
7281
|
+
cleanup = undefined;
|
|
7230
7282
|
try {
|
|
7231
|
-
|
|
7283
|
+
untrack(previousCleanup);
|
|
7232
7284
|
}
|
|
7233
7285
|
catch (error) {
|
|
7234
7286
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -7239,6 +7291,7 @@
|
|
|
7239
7291
|
currentEffect = execute;
|
|
7240
7292
|
// Store dependencies for cleanup
|
|
7241
7293
|
execute.__dependencies = dependencies;
|
|
7294
|
+
execute.__versions = versions;
|
|
7242
7295
|
try {
|
|
7243
7296
|
const nextCleanup = fn();
|
|
7244
7297
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -7248,6 +7301,7 @@
|
|
|
7248
7301
|
// Don't throw - allow other effects to continue
|
|
7249
7302
|
}
|
|
7250
7303
|
finally {
|
|
7304
|
+
initialized = true;
|
|
7251
7305
|
currentEffect = prevEffect;
|
|
7252
7306
|
effectDepth--;
|
|
7253
7307
|
runningEffects.delete(execute);
|
|
@@ -7264,14 +7318,17 @@
|
|
|
7264
7318
|
if (!active)
|
|
7265
7319
|
return;
|
|
7266
7320
|
active = false;
|
|
7321
|
+
effectQueue.delete(execute);
|
|
7322
|
+
batchedEffects.delete(execute);
|
|
7267
7323
|
// Remove from all dependencies
|
|
7268
7324
|
dependencies.forEach(depSet => {
|
|
7269
7325
|
depSet.delete(execute);
|
|
7270
7326
|
});
|
|
7271
7327
|
dependencies.clear();
|
|
7328
|
+
versions.clear();
|
|
7272
7329
|
if (cleanup) {
|
|
7273
7330
|
try {
|
|
7274
|
-
cleanup
|
|
7331
|
+
untrack(cleanup);
|
|
7275
7332
|
}
|
|
7276
7333
|
catch (error) {
|
|
7277
7334
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -7331,6 +7388,8 @@
|
|
|
7331
7388
|
const effects = Array.from(batchedEffects);
|
|
7332
7389
|
batchedEffects.clear();
|
|
7333
7390
|
effects.forEach(effect => {
|
|
7391
|
+
// This batch also settles any earlier queued write to this observer.
|
|
7392
|
+
effectQueue.delete(effect);
|
|
7334
7393
|
try {
|
|
7335
7394
|
effect();
|
|
7336
7395
|
}
|
|
@@ -15361,7 +15420,7 @@
|
|
|
15361
15420
|
portalCreate,
|
|
15362
15421
|
portalDestroy,
|
|
15363
15422
|
setCspNonce,
|
|
15364
|
-
version: '0.4.
|
|
15423
|
+
version: '0.4.1'
|
|
15365
15424
|
};
|
|
15366
15425
|
|
|
15367
15426
|
setExpressionRuntime(cspExpressionRuntime);
|