Skip to content

Commit ad5d6f4

Browse files
committed
fix logic
1 parent bf6af3b commit ad5d6f4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/core/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@ export class Signal<T = any> {
4343
}
4444

4545
peek() {
46-
if (currentSignal && currentSignal._canActivate && this._deps.size === 0) {
46+
const shouldActivate = !currentSignal || currentSignal._canActivate;
47+
if (shouldActivate && this._deps.size === 0) {
4748
activate(this);
4849
}
4950
return this._value;
5051
}
5152

5253
get value() {
53-
if (!currentSignal) {
54-
return this._value;
54+
const shouldActivate = !currentSignal || currentSignal._canActivate;
55+
if (shouldActivate && this._deps.size === 0) {
56+
activate(this);
5557
}
58+
5659
// If we read a signal outside of a computed we have no way
5760
// to unsubscribe from that. So we assume that the user wants
5861
// to get the value immediately like for testing.
59-
if (currentSignal._canActivate && this._deps.size === 0) {
60-
activate(this);
62+
if (!currentSignal) {
63+
return this._value;
6164
}
6265

6366
// subscribe the current computed to this signal:

0 commit comments

Comments
 (0)