@@ -42,7 +42,7 @@ export interface ModelSignal<T> extends WritableSignal<T> {
4242 [ ɵINPUT_SIGNAL_BRAND_WRITE_TYPE ] : T ;
4343
4444 /**
45- * Subscribes to changes in the model's value.
45+ * Subscribes to changes in the model's value. Used by listener instructions at runtime.
4646 * @internal
4747 */
4848 subscribe ( callback : ( value : T ) => void ) : { unsubscribe : ( ) => void } ;
@@ -56,6 +56,7 @@ export interface ModelSignal<T> extends WritableSignal<T> {
5656 * @param options Additional options for the model.
5757 */
5858export function createModelSignal < T > ( initialValue : T ) : ModelSignal < T > {
59+ const subscriptions : ( ( value : T ) => void ) [ ] = [ ] ;
5960 const node : ModelSignalNode < T > = Object . create ( MODEL_SIGNAL_NODE ) ;
6061
6162 node . value = initialValue ;
@@ -73,8 +74,6 @@ export function createModelSignal<T>(initialValue: T): ModelSignal<T> {
7374 }
7475
7576 function notifySubscribers ( value : T ) : void {
76- const subscriptions = node . subscriptions ;
77-
7877 for ( let i = 0 ; i < subscriptions . length ; i ++ ) {
7978 subscriptions [ i ] ( value ) ;
8079 }
@@ -95,15 +94,15 @@ export function createModelSignal<T>(initialValue: T): ModelSignal<T> {
9594 } ;
9695
9796 getter . subscribe = ( callback : ( value : T ) => void ) => {
98- node . subscriptions . push ( callback ) ;
97+ subscriptions . push ( callback ) ;
9998
10099 // TODO(crisbeto): figure out if we can get rid of the object literal.
101100 return {
102101 unsubscribe : ( ) => {
103- const index = node . subscriptions . indexOf ( callback ) ;
102+ const index = subscriptions . indexOf ( callback ) ;
104103
105104 if ( index > - 1 ) {
106- node . subscriptions . splice ( index , 1 ) ;
105+ subscriptions . splice ( index , 1 ) ;
107106 }
108107 }
109108 } ;
0 commit comments