You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use null for computing rather than undefined (#235)
* Use `null` rather than `undefined` on `computing`
This is consistent with the type specified for `currentComputed()`.
* Specify the (trivial) semantics of `currentComputed()`
Copy file name to clipboardexpand all lines: README.md
+7-3
Original file line number
Diff line number
Diff line change
@@ -442,7 +442,7 @@ Some aspects of the algorithm:
442
442
443
443
Signal algorithms need to reference certain global state. This state is global for the entire thread, or "agent".
444
444
445
-
- `computing`: The innermost computed or effect Signal currently being reevaluated due to a `.get` or `.run` call, or `undefined`. Initially `undefined`.
445
+
- `computing`: The innermost computed or effect Signal currently being reevaluated due to a `.get` or `.run` call, or `null`. Initially `null`.
446
446
- `frozen`: Boolean denoting whether there is a callback currently executing which requires that the graph not be modified. Initially `false`.
447
447
- `generation`: An incrementing integer, starting at 0, used to track how current a value is while avoiding circularities.
448
448
@@ -549,7 +549,7 @@ With [AsyncContext](https://github.com/tc39/proposal-async-context), the callbac
549
549
#### Method: `Signal.Computed.prototype.get`
550
550
551
551
1. If the current execution context is `frozen` or if this Signal has the state `~computing~`, or if this signal is an Effect and `computing` a computed Signal, throw an exception.
552
-
1. If `computing` is not `undefined`, add this Signal to `computing`'s `sources` set.
552
+
1. If `computing` is not `null`, add this Signal to `computing`'s `sources` set.
553
553
1. NOTE: We do not add `computing` to this Signal's `sinks` set until/unless it becomes watched by a Watcher.
554
554
1. If this Signal's state is `~dirty~` or `~checked~`: Repeat the following steps until this Signal is `~clean~`:
555
555
1. Recurse up via `sources` to find the deepest, left-most (i.e. earliest observed) recursive source which is marked `~dirty~` (cutting off search when hitting a `~clean~` Signal, and including this Signal as the last thing to search).
@@ -632,13 +632,17 @@ With [AsyncContext](https://github.com/tc39/proposal-async-context), the callbac
632
632
### Method: `Signal.subtle.untrack(cb)`
633
633
634
634
1. Let `c` be the execution context's current `computing` state.
635
-
1. Set `computing` to undefined.
635
+
1. Set `computing` to null.
636
636
1. Call `cb`.
637
637
1. Restore `computing` to `c` (even if `cb` threw an exception).
638
638
1. Return the return value of `cb` (rethrowing any exception).
639
639
640
640
Note: untrack doesn't get you out of the `frozen` state, which is maintained strictly.
641
641
642
+
### Method: `Signal.subtle.currentComputed()`
643
+
644
+
1. Return the current `computing` value.
645
+
642
646
### Common algorithms
643
647
644
648
##### Algorithm: recalculate dirty computed Signal
0 commit comments