While True binding? Update On bindings? #8543
Description
I'm not sure if this has been brought up before; I couldn't find any prior discussion. Maybe someone can point me in the correct way.
We now have one-time binding with {{ ::foo }}
.
Another use-case I'd consider very useful is a binding that will continue updating while a certain expression is true, and then become unbound once it returns false.
For example:
// Controller
$scope.Job = {
status: 'running',
isActive: function () {
return ['finished', 'error'].indexOf(this.status) === -1;
}
};
<!-- View -->
<div>
{{ Job.isActive()::Job.status }}
</div>
In this case, once Job.status has been update to finished or error, it can remove the watcher because Job.isActive()
will return false, so it knows that it will no longer continue changing.
I have a lot of bindings in which I only want temporary bindings, this would help to reduce the number of watchers.
Would there be any interest in having some sort of concept of manually triggered bindings? For a lot of my data sets I'll usually know when they're changing (for example, if it's data coming from the server that I'm refreshing), so instead of having to check them in every cycle, I could manually trigger when they've changed. It's not great, and it's probably not that useful now that there's Object.observe; has it been discussed? I've considered implementing a directive to sorta do this for me, by registering listeners and emitting events through a service or something along those lines.