@@ -616,7 +616,7 @@ export class Scope {
616616 * function is invoked when changes to that property are detected.
617617 *
618618 * @param {string } watchProp - An expression to be watched in the context of this model.
619- * @param {import('./interface.ts').ListenerFunction } [listenerFn] - A function to execute when changes are detected on watched context.
619+ * @param {ng.ListenerFn } [listenerFn] - A function to execute when changes are detected on watched context.
620620 * @param {boolean } [lazy] - A flag to indicate if the listener should be invoked immediately. Defaults to false.
621621 */
622622 $watch ( watchProp , listenerFn , lazy = false ) {
@@ -638,7 +638,7 @@ export class Scope {
638638 return ( ) => { } ;
639639 }
640640
641- /** @type {import('./interface.ts') .Listener } */
641+ /** @type {ng .Listener } */
642642 const listener = {
643643 originalTarget : this . $target ,
644644 listenerFn : listenerFn ,
@@ -696,13 +696,34 @@ export class Scope {
696696 }
697697 // 6
698698 case ASTType . BinaryExpression : {
699- let expr = get . decoratedNode . body [ 0 ] . expression . toWatch [ 0 ] ;
700- key = expr . property ? expr . property . name : expr . name ;
701- if ( ! key ) {
702- throw new Error ( "Unable to determine key" ) ;
699+ if ( get . decoratedNode . body [ 0 ] . expression . isPure ) {
700+ let expr = get . decoratedNode . body [ 0 ] . expression . toWatch [ 0 ] ;
701+ key = expr . property ? expr . property . name : expr . name ;
702+ if ( ! key ) {
703+ throw new Error ( "Unable to determine key" ) ;
704+ }
705+ listener . property . push ( key ) ;
706+ break ;
707+ } else {
708+ let keys = [ ] ;
709+ get . decoratedNode . body [ 0 ] . expression . toWatch . forEach ( ( x ) => {
710+ const k = x . property ? x . property . name : x . name ;
711+ if ( ! k ) {
712+ throw new Error ( "Unable to determine key" ) ;
713+ }
714+ keys . push ( k ) ;
715+ } ) ;
716+ keys . forEach ( ( key ) => {
717+ this . #registerKey( key , listener ) ;
718+ this . #scheduleListener( [ listener ] ) ;
719+ } ) ;
720+
721+ return ( ) => {
722+ keys . forEach ( ( key ) => {
723+ this . #deregisterKey( key , listener . id ) ;
724+ } ) ;
725+ } ;
703726 }
704- listener . property . push ( key ) ;
705- break ;
706727 }
707728 // 7
708729 case ASTType . UnaryExpression : {
0 commit comments