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

While True binding? Update On bindings? #8543

Closed
cesarandreu opened this issue Aug 8, 2014 · 5 comments
Closed

While True binding? Update On bindings? #8543

cesarandreu opened this issue Aug 8, 2014 · 5 comments

Comments

@cesarandreu
Copy link

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.

@caitp
Copy link
Contributor

caitp commented Aug 8, 2014

so, there has been some talk about supporting groups of watches which can be enabled/disabled imperatively. It's been thrown away for now, but might come back in the future (we do want it).

This, however, is essentially "watch this one expression, and if it's truthy, also watch this other expression", which seems kinda weird, and not at all a performance enhancement

@cesarandreu
Copy link
Author

Maybe I wasn't clear, I was thinking: watch Job.status while Job.isActive() is truthy. Once Job.isActive() stops being truthy, remove both watches. Even if Job.isActive() were to become truthy later, it'll no longer be watched.

Basically, stop watching once a certain condition is met, because I know it's no longer going to get updated.

@btford
Copy link
Contributor

btford commented Aug 18, 2014

Can't you do this with {{ ::Job.isActive() && Job.status }} ?

@btford btford added this to the Backlog milestone Aug 18, 2014
@caitp
Copy link
Contributor

caitp commented Aug 18, 2014

only if Job.isActive() returns undefined until it's true, which seems unlikely unless the code is specifically designed for this

@Narretz
Copy link
Contributor

Narretz commented Apr 27, 2017

It should be possible to achieve this with suspending watchers on the scope, which is still under consideration: #10658

@Narretz Narretz closed this as completed Apr 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants