@rlabs-inc/signals 1.4.3 → 1.5.0
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 +12 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -11
- package/dist/index.mjs +78 -11
- package/dist/primitives/bind.d.ts +24 -0
- package/dist/primitives/bind.d.ts.map +1 -1
- package/dist/reactivity/tracking.d.ts +8 -0
- package/dist/reactivity/tracking.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,7 +257,18 @@ console.log(readonly.value) // 0
|
|
|
257
257
|
// Check if a value is a binding
|
|
258
258
|
isBinding(maybeBinding) // true or false
|
|
259
259
|
|
|
260
|
-
// Get value from binding or return value directly
|
|
260
|
+
// Get value from binding, signal, derived, or return plain value directly
|
|
261
|
+
// Works with ALL reactive types for unified value access
|
|
262
|
+
const count = signal(42)
|
|
263
|
+
const doubled = derived(() => count.value * 2)
|
|
264
|
+
const bound = bind(count)
|
|
265
|
+
|
|
266
|
+
unwrap(count) // 42 (extracts .value from signal)
|
|
267
|
+
unwrap(doubled) // 84 (extracts .value from derived)
|
|
268
|
+
unwrap(bound) // 42 (extracts .value from binding)
|
|
269
|
+
unwrap('static') // 'static' (returns plain values as-is)
|
|
270
|
+
|
|
271
|
+
// Great for mapping mixed arrays
|
|
261
272
|
const arr: (string | Binding<string>)[] = ['static', bind(signal('dynamic'))]
|
|
262
273
|
arr.map(unwrap) // ['static', 'dynamic']
|
|
263
274
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { signal, source, mutableSource, state, stateRaw } from './primitives/signal.js';
|
|
2
2
|
export { derived, createDerived, disconnectDerived } from './primitives/derived.js';
|
|
3
3
|
export { effect, createEffect, updateEffect, destroyEffect } from './primitives/effect.js';
|
|
4
|
-
export { bind, bindReadonly, isBinding, unwrap, signals } from './primitives/bind.js';
|
|
4
|
+
export { bind, bindReadonly, isBinding, unwrap, signals, disconnectBinding, bindingHasInternalSource } from './primitives/bind.js';
|
|
5
5
|
export { linkedSignal, isLinkedSignal } from './primitives/linked.js';
|
|
6
6
|
export { createSelector } from './primitives/selector.js';
|
|
7
7
|
export { effectScope, getCurrentScope, onScopeDispose } from './primitives/scope.js';
|
|
@@ -12,7 +12,7 @@ export { equals, safeEquals, safeNotEqual, shallowEquals, createEquals, neverEqu
|
|
|
12
12
|
export { ReactiveMap } from './collections/map.js';
|
|
13
13
|
export { ReactiveSet } from './collections/set.js';
|
|
14
14
|
export { ReactiveDate } from './collections/date.js';
|
|
15
|
-
export { get, set, isDirty, setSignalStatus, markReactions, updateReaction, removeReactions, } from './reactivity/tracking.js';
|
|
15
|
+
export { get, set, isDirty, setSignalStatus, markReactions, updateReaction, removeReactions, disconnectSource, } from './reactivity/tracking.js';
|
|
16
16
|
export { DERIVED, EFFECT, RENDER_EFFECT, ROOT_EFFECT, BRANCH_EFFECT, USER_EFFECT, BLOCK_EFFECT, CLEAN, DIRTY, MAYBE_DIRTY, REACTION_IS_UPDATING, DESTROYED, INERT, EFFECT_RAN, EFFECT_PRESERVED, UNOWNED, DISCONNECTED, UNINITIALIZED, STALE_REACTION, STATE_SYMBOL, REACTIVE_MARKER, BINDING_SYMBOL, LINKED_SYMBOL, } from './core/constants.js';
|
|
17
17
|
export { activeReaction, activeEffect, untracking, writeVersion, readVersion, batchDepth, setActiveReaction, setActiveEffect, setUntracking, incrementWriteVersion, incrementReadVersion, incrementBatchDepth, decrementBatchDepth, getReadVersion, getWriteVersion, getBatchDepth, } from './core/globals.js';
|
|
18
18
|
export type { Signal, Source, Reaction, Derived, Effect, Value, ReadableSignal, WritableSignal, DerivedSignal, DisposeFn, CleanupFn, EffectFn, Equals, Uninitialized, ExtractInner, } from './core/types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources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A;AACpE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AACrF,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,9 @@ __export(exports_src, {
|
|
|
75
75
|
equals: () => equals,
|
|
76
76
|
effectScope: () => effectScope,
|
|
77
77
|
effect: () => effect,
|
|
78
|
+
disconnectSource: () => disconnectSource,
|
|
78
79
|
disconnectDerived: () => disconnectDerived,
|
|
80
|
+
disconnectBinding: () => disconnectBinding,
|
|
79
81
|
destroyEffect: () => destroyEffect,
|
|
80
82
|
derived: () => derived,
|
|
81
83
|
decrementBatchDepth: () => decrementBatchDepth,
|
|
@@ -83,6 +85,7 @@ __export(exports_src, {
|
|
|
83
85
|
createEquals: () => createEquals,
|
|
84
86
|
createEffect: () => createEffect,
|
|
85
87
|
createDerived: () => createDerived,
|
|
88
|
+
bindingHasInternalSource: () => bindingHasInternalSource,
|
|
86
89
|
bindReadonly: () => bindReadonly,
|
|
87
90
|
bind: () => bind,
|
|
88
91
|
batchDepth: () => batchDepth,
|
|
@@ -592,6 +595,26 @@ function updateDerived(derived) {
|
|
|
592
595
|
function setUpdateDerivedImpl(impl) {
|
|
593
596
|
updateDerivedImpl = impl;
|
|
594
597
|
}
|
|
598
|
+
function disconnectSource(source) {
|
|
599
|
+
const reactions = source.reactions;
|
|
600
|
+
if (reactions !== null) {
|
|
601
|
+
for (let i = 0;i < reactions.length; i++) {
|
|
602
|
+
const reaction = reactions[i];
|
|
603
|
+
const deps = reaction.deps;
|
|
604
|
+
if (deps !== null) {
|
|
605
|
+
const idx = deps.indexOf(source);
|
|
606
|
+
if (idx !== -1) {
|
|
607
|
+
const last = deps.length - 1;
|
|
608
|
+
if (idx !== last) {
|
|
609
|
+
deps[idx] = deps[last];
|
|
610
|
+
}
|
|
611
|
+
deps.pop();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
source.reactions = null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
595
618
|
function removeReactions(reaction, start) {
|
|
596
619
|
const deps = reaction.deps;
|
|
597
620
|
if (deps === null)
|
|
@@ -1246,8 +1269,9 @@ effect.tracking = function effectTracking() {
|
|
|
1246
1269
|
return activeEffect !== null;
|
|
1247
1270
|
};
|
|
1248
1271
|
// src/primitives/bind.ts
|
|
1272
|
+
var BINDING_SOURCE_SYMBOL = Symbol("binding.source");
|
|
1249
1273
|
var bindingCleanup = new FinalizationRegistry((internalSource) => {
|
|
1250
|
-
internalSource
|
|
1274
|
+
disconnectSource(internalSource);
|
|
1251
1275
|
});
|
|
1252
1276
|
function isBinding(value) {
|
|
1253
1277
|
return value !== null && typeof value === "object" && BINDING_SYMBOL in value;
|
|
@@ -1258,31 +1282,59 @@ function isSignal(value) {
|
|
|
1258
1282
|
function isGetter(value) {
|
|
1259
1283
|
return typeof value === "function";
|
|
1260
1284
|
}
|
|
1285
|
+
function isStaticPrimitive(value) {
|
|
1286
|
+
const type = typeof value;
|
|
1287
|
+
return value === null || value === undefined || type === "number" || type === "string" || type === "boolean";
|
|
1288
|
+
}
|
|
1261
1289
|
function bind(source2) {
|
|
1262
1290
|
if (isGetter(source2)) {
|
|
1263
|
-
|
|
1291
|
+
const getterBinding = {
|
|
1264
1292
|
[BINDING_SYMBOL]: true,
|
|
1293
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1265
1294
|
get value() {
|
|
1266
1295
|
return source2();
|
|
1267
1296
|
}
|
|
1268
1297
|
};
|
|
1298
|
+
return getterBinding;
|
|
1269
1299
|
}
|
|
1270
|
-
let actualSource;
|
|
1271
|
-
let internalSource = null;
|
|
1272
1300
|
if (isBinding(source2) || isSignal(source2)) {
|
|
1273
|
-
actualSource = source2;
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1301
|
+
const actualSource = source2;
|
|
1302
|
+
const forwardBinding = {
|
|
1303
|
+
[BINDING_SYMBOL]: true,
|
|
1304
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1305
|
+
get value() {
|
|
1306
|
+
return actualSource.value;
|
|
1307
|
+
},
|
|
1308
|
+
set value(v) {
|
|
1309
|
+
actualSource.value = v;
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
return forwardBinding;
|
|
1313
|
+
}
|
|
1314
|
+
if (isStaticPrimitive(source2)) {
|
|
1315
|
+
let staticValue = source2;
|
|
1316
|
+
const staticBinding = {
|
|
1317
|
+
[BINDING_SYMBOL]: true,
|
|
1318
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1319
|
+
get value() {
|
|
1320
|
+
return staticValue;
|
|
1321
|
+
},
|
|
1322
|
+
set value(v) {
|
|
1323
|
+
staticValue = v;
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
return staticBinding;
|
|
1278
1327
|
}
|
|
1328
|
+
const sig = signal(source2);
|
|
1329
|
+
const internalSource = getSource(sig) ?? null;
|
|
1279
1330
|
const binding = {
|
|
1280
1331
|
[BINDING_SYMBOL]: true,
|
|
1332
|
+
[BINDING_SOURCE_SYMBOL]: internalSource,
|
|
1281
1333
|
get value() {
|
|
1282
|
-
return
|
|
1334
|
+
return sig.value;
|
|
1283
1335
|
},
|
|
1284
1336
|
set value(v) {
|
|
1285
|
-
|
|
1337
|
+
sig.value = v;
|
|
1286
1338
|
}
|
|
1287
1339
|
};
|
|
1288
1340
|
if (internalSource !== null) {
|
|
@@ -1290,6 +1342,18 @@ function bind(source2) {
|
|
|
1290
1342
|
}
|
|
1291
1343
|
return binding;
|
|
1292
1344
|
}
|
|
1345
|
+
function disconnectBinding(binding) {
|
|
1346
|
+
if (binding === null || binding === undefined)
|
|
1347
|
+
return;
|
|
1348
|
+
const internalSource = binding[BINDING_SOURCE_SYMBOL];
|
|
1349
|
+
if (internalSource !== null && internalSource !== undefined) {
|
|
1350
|
+
disconnectSource(internalSource);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
function bindingHasInternalSource(binding) {
|
|
1354
|
+
const internalSource = binding[BINDING_SOURCE_SYMBOL];
|
|
1355
|
+
return internalSource !== null && internalSource !== undefined;
|
|
1356
|
+
}
|
|
1293
1357
|
function bindReadonly(source2) {
|
|
1294
1358
|
return {
|
|
1295
1359
|
[BINDING_SYMBOL]: true,
|
|
@@ -1302,6 +1366,9 @@ function unwrap(value) {
|
|
|
1302
1366
|
if (isBinding(value)) {
|
|
1303
1367
|
return value.value;
|
|
1304
1368
|
}
|
|
1369
|
+
if (value !== null && typeof value === "object" && "value" in value) {
|
|
1370
|
+
return value.value;
|
|
1371
|
+
}
|
|
1305
1372
|
return value;
|
|
1306
1373
|
}
|
|
1307
1374
|
function signals(initial) {
|
package/dist/index.mjs
CHANGED
|
@@ -471,6 +471,26 @@ function updateDerived(derived) {
|
|
|
471
471
|
function setUpdateDerivedImpl(impl) {
|
|
472
472
|
updateDerivedImpl = impl;
|
|
473
473
|
}
|
|
474
|
+
function disconnectSource(source) {
|
|
475
|
+
const reactions = source.reactions;
|
|
476
|
+
if (reactions !== null) {
|
|
477
|
+
for (let i = 0;i < reactions.length; i++) {
|
|
478
|
+
const reaction = reactions[i];
|
|
479
|
+
const deps = reaction.deps;
|
|
480
|
+
if (deps !== null) {
|
|
481
|
+
const idx = deps.indexOf(source);
|
|
482
|
+
if (idx !== -1) {
|
|
483
|
+
const last = deps.length - 1;
|
|
484
|
+
if (idx !== last) {
|
|
485
|
+
deps[idx] = deps[last];
|
|
486
|
+
}
|
|
487
|
+
deps.pop();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
source.reactions = null;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
474
494
|
function removeReactions(reaction, start) {
|
|
475
495
|
const deps = reaction.deps;
|
|
476
496
|
if (deps === null)
|
|
@@ -1125,8 +1145,9 @@ effect.tracking = function effectTracking() {
|
|
|
1125
1145
|
return activeEffect !== null;
|
|
1126
1146
|
};
|
|
1127
1147
|
// src/primitives/bind.ts
|
|
1148
|
+
var BINDING_SOURCE_SYMBOL = Symbol("binding.source");
|
|
1128
1149
|
var bindingCleanup = new FinalizationRegistry((internalSource) => {
|
|
1129
|
-
internalSource
|
|
1150
|
+
disconnectSource(internalSource);
|
|
1130
1151
|
});
|
|
1131
1152
|
function isBinding(value) {
|
|
1132
1153
|
return value !== null && typeof value === "object" && BINDING_SYMBOL in value;
|
|
@@ -1137,31 +1158,59 @@ function isSignal(value) {
|
|
|
1137
1158
|
function isGetter(value) {
|
|
1138
1159
|
return typeof value === "function";
|
|
1139
1160
|
}
|
|
1161
|
+
function isStaticPrimitive(value) {
|
|
1162
|
+
const type = typeof value;
|
|
1163
|
+
return value === null || value === undefined || type === "number" || type === "string" || type === "boolean";
|
|
1164
|
+
}
|
|
1140
1165
|
function bind(source2) {
|
|
1141
1166
|
if (isGetter(source2)) {
|
|
1142
|
-
|
|
1167
|
+
const getterBinding = {
|
|
1143
1168
|
[BINDING_SYMBOL]: true,
|
|
1169
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1144
1170
|
get value() {
|
|
1145
1171
|
return source2();
|
|
1146
1172
|
}
|
|
1147
1173
|
};
|
|
1174
|
+
return getterBinding;
|
|
1148
1175
|
}
|
|
1149
|
-
let actualSource;
|
|
1150
|
-
let internalSource = null;
|
|
1151
1176
|
if (isBinding(source2) || isSignal(source2)) {
|
|
1152
|
-
actualSource = source2;
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1177
|
+
const actualSource = source2;
|
|
1178
|
+
const forwardBinding = {
|
|
1179
|
+
[BINDING_SYMBOL]: true,
|
|
1180
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1181
|
+
get value() {
|
|
1182
|
+
return actualSource.value;
|
|
1183
|
+
},
|
|
1184
|
+
set value(v) {
|
|
1185
|
+
actualSource.value = v;
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
return forwardBinding;
|
|
1189
|
+
}
|
|
1190
|
+
if (isStaticPrimitive(source2)) {
|
|
1191
|
+
let staticValue = source2;
|
|
1192
|
+
const staticBinding = {
|
|
1193
|
+
[BINDING_SYMBOL]: true,
|
|
1194
|
+
[BINDING_SOURCE_SYMBOL]: null,
|
|
1195
|
+
get value() {
|
|
1196
|
+
return staticValue;
|
|
1197
|
+
},
|
|
1198
|
+
set value(v) {
|
|
1199
|
+
staticValue = v;
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
return staticBinding;
|
|
1157
1203
|
}
|
|
1204
|
+
const sig = signal(source2);
|
|
1205
|
+
const internalSource = getSource(sig) ?? null;
|
|
1158
1206
|
const binding = {
|
|
1159
1207
|
[BINDING_SYMBOL]: true,
|
|
1208
|
+
[BINDING_SOURCE_SYMBOL]: internalSource,
|
|
1160
1209
|
get value() {
|
|
1161
|
-
return
|
|
1210
|
+
return sig.value;
|
|
1162
1211
|
},
|
|
1163
1212
|
set value(v) {
|
|
1164
|
-
|
|
1213
|
+
sig.value = v;
|
|
1165
1214
|
}
|
|
1166
1215
|
};
|
|
1167
1216
|
if (internalSource !== null) {
|
|
@@ -1169,6 +1218,18 @@ function bind(source2) {
|
|
|
1169
1218
|
}
|
|
1170
1219
|
return binding;
|
|
1171
1220
|
}
|
|
1221
|
+
function disconnectBinding(binding) {
|
|
1222
|
+
if (binding === null || binding === undefined)
|
|
1223
|
+
return;
|
|
1224
|
+
const internalSource = binding[BINDING_SOURCE_SYMBOL];
|
|
1225
|
+
if (internalSource !== null && internalSource !== undefined) {
|
|
1226
|
+
disconnectSource(internalSource);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
function bindingHasInternalSource(binding) {
|
|
1230
|
+
const internalSource = binding[BINDING_SOURCE_SYMBOL];
|
|
1231
|
+
return internalSource !== null && internalSource !== undefined;
|
|
1232
|
+
}
|
|
1172
1233
|
function bindReadonly(source2) {
|
|
1173
1234
|
return {
|
|
1174
1235
|
[BINDING_SYMBOL]: true,
|
|
@@ -1181,6 +1242,9 @@ function unwrap(value) {
|
|
|
1181
1242
|
if (isBinding(value)) {
|
|
1182
1243
|
return value.value;
|
|
1183
1244
|
}
|
|
1245
|
+
if (value !== null && typeof value === "object" && "value" in value) {
|
|
1246
|
+
return value.value;
|
|
1247
|
+
}
|
|
1184
1248
|
return value;
|
|
1185
1249
|
}
|
|
1186
1250
|
function signals(initial) {
|
|
@@ -1868,7 +1932,9 @@ export {
|
|
|
1868
1932
|
equals,
|
|
1869
1933
|
effectScope,
|
|
1870
1934
|
effect,
|
|
1935
|
+
disconnectSource,
|
|
1871
1936
|
disconnectDerived,
|
|
1937
|
+
disconnectBinding,
|
|
1872
1938
|
destroyEffect,
|
|
1873
1939
|
derived,
|
|
1874
1940
|
decrementBatchDepth,
|
|
@@ -1876,6 +1942,7 @@ export {
|
|
|
1876
1942
|
createEquals,
|
|
1877
1943
|
createEffect,
|
|
1878
1944
|
createDerived,
|
|
1945
|
+
bindingHasInternalSource,
|
|
1879
1946
|
bindReadonly,
|
|
1880
1947
|
bind,
|
|
1881
1948
|
batchDepth,
|
|
@@ -24,6 +24,30 @@ export declare function bind<T>(source: Binding<T>): Binding<T>;
|
|
|
24
24
|
export declare function bind<T>(source: ReadonlyBinding<T>): ReadonlyBinding<T>;
|
|
25
25
|
export declare function bind<T>(source: () => T): ReadonlyBinding<T>;
|
|
26
26
|
export declare function bind<T>(source: T): Binding<ExtractInner<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* Disconnect a binding from the reactive graph.
|
|
29
|
+
*
|
|
30
|
+
* In most cases, this is NOT needed because:
|
|
31
|
+
* 1. Static primitives (numbers, strings, booleans) don't create internal signals
|
|
32
|
+
* 2. Bindings to existing signals forward to them (no internal source)
|
|
33
|
+
* 3. FinalizationRegistry handles cleanup when objects are GC'd
|
|
34
|
+
*
|
|
35
|
+
* Use this ONLY when you have circular references that prevent GC,
|
|
36
|
+
* such as when a binding's internal source is tracked by a long-lived derived.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const binding = bind(someNonPrimitiveValue)
|
|
41
|
+
* // ... later, when cleaning up:
|
|
42
|
+
* disconnectBinding(binding) // Breaks reactive links, allows GC
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function disconnectBinding(binding: Binding<unknown> | ReadonlyBinding<unknown> | null | undefined): void;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a binding has an internal source that may need cleanup.
|
|
48
|
+
* Static primitives and forwarding bindings return false.
|
|
49
|
+
*/
|
|
50
|
+
export declare function bindingHasInternalSource(binding: Binding<unknown> | ReadonlyBinding<unknown>): boolean;
|
|
27
51
|
/**
|
|
28
52
|
* Create an explicitly read-only binding.
|
|
29
53
|
* Attempting to write will throw an error at runtime.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../src/primitives/bind.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAU,YAAY,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../src/primitives/bind.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAU,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAoC5F;;;GAGG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,IAAI,KAAK,IAAI,CAAC,CAAA;IACd,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,EAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAA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,OAAO,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAUvE;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvD,OAAO,EAAE,CAAC,GACT;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAU1C"}
|
|
@@ -39,6 +39,14 @@ export declare function setSignalStatus(signal: {
|
|
|
39
39
|
export declare function isDirty(reaction: Reaction): boolean;
|
|
40
40
|
export declare function updateDerived(derived: Derived): void;
|
|
41
41
|
export declare function setUpdateDerivedImpl(impl: (derived: Derived) => void): void;
|
|
42
|
+
/**
|
|
43
|
+
* Disconnect a source from all its reactions.
|
|
44
|
+
* This breaks the circular reference between Source.reactions and Reaction.deps,
|
|
45
|
+
* allowing both to be garbage collected.
|
|
46
|
+
*
|
|
47
|
+
* Use this when disposing of a signal/binding that was tracked by deriveds/effects.
|
|
48
|
+
*/
|
|
49
|
+
export declare function disconnectSource(source: Source): void;
|
|
42
50
|
/**
|
|
43
51
|
* Remove a reaction from its dependencies, starting at the given index
|
|
44
52
|
* Uses swap-and-pop for O(1) removal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../../src/reactivity/tracking.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAkCjE;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAiD3C;AAoGD;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,C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Ae,CAAC,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAE3E;AAMD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAoGnD;AAWD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAEpD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAE3E;AAMD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAsBrD;AAMD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOvE;AA8BD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAmG1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rlabs-inc/signals",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Production-grade fine-grained reactivity for TypeScript. A complete standalone mirror of Svelte 5's reactivity system - signals, effects, derived values, deep reactivity, reactive collections, and reactive bindings.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|