Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

alternate $watch for multiple values #6776

Closed
valtron opened this issue Mar 20, 2014 · 1 comment
Closed

alternate $watch for multiple values #6776

valtron opened this issue Mar 20, 2014 · 1 comment

Comments

@valtron
Copy link

valtron commented Mar 20, 2014

I propose adding another syntax for $watch:

$scope.$watch(['prop', 'foo.bar'], fn);

which would mean the same thing as:

$scope.$watch('prop', fn);
$scope.$watch('foo.bar', fn);

Currently, it's possible to do the same thing using $watchCollection, however:

  • $watchCollection supports arbitrary collections; multi-$watch can be optimized better because it's always watching an array, whose size is fixed
  • writing the array inside of a string ('[prop, foo.bar]') looks kludgy

But I think the reason for having multi-$watch is mainly semantics (i.e. better communication of intent):

  • $watch(['a', 'b'], fn): fn depends on multiple things: a and b
  • $watchCollection('collection', fn): fn depends on the contents of one thing: collection
@rodyhaddad
Copy link
Contributor

#6598 will add $scope.$watchSet([exp1, exp2], fn). That's exactly what you're looking for! :-)

Though the naming might change (feel free to give your suggestions in the PR), the PR should land in the coming 1.3.0-beta releases

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants