Skip to content

Commit 53dcfe1

Browse files
committed
Add in computed
1 parent 30a196b commit 53dcfe1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/core/src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -537,19 +537,21 @@ declare class Computed<T = any> extends Signal<T> {
537537
_globalVersion: number;
538538
_flags: number;
539539

540-
constructor(fn: () => T);
540+
constructor(fn: () => T, options?: SignalOptions<T>);
541541

542542
_notify(): void;
543543
get value(): T;
544544
}
545545

546-
function Computed(this: Computed, fn: () => unknown) {
546+
function Computed(this: Computed, fn: () => unknown, options?: SignalOptions) {
547547
Signal.call(this, undefined);
548548

549549
this._fn = fn;
550550
this._sources = undefined;
551551
this._globalVersion = globalVersion - 1;
552552
this._flags = OUTDATED;
553+
this._watched = options?.watched;
554+
this._unwatched = options?.unwatched;
553555
}
554556

555557
Computed.prototype = new Signal() as Computed;
@@ -626,9 +628,8 @@ Computed.prototype._subscribe = function (node) {
626628

627629
Computed.prototype._unsubscribe = function (node) {
628630
// Only run the unsubscribe step if the computed signal has any subscribers.
631+
Signal.prototype._unsubscribe.call(this, node);
629632
if (this._targets !== undefined) {
630-
Signal.prototype._unsubscribe.call(this, node);
631-
632633
// Computed signal unsubscribes from its dependencies when it loses its last subscriber.
633634
// This makes it possible for unreferences subgraphs of computed signals to get garbage collected.
634635
if (this._targets === undefined) {

0 commit comments

Comments
 (0)