angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Add `scope.$suspend()` and `scope.$resume()` like methods

Open caiotoon opened this issue 13 years ago • 3 comments

What about a way to prevent a scope (and its children) to participate on scope $digest cycles?

One may not need/want to rely on ng-view and $route, and still be able to prevent that unseen content become digested over and over again. I asked around a bit and for my use case, there is the solution of using ng-switch, or maybe mimic its behavior, as I remove the content from the screen. But let's consider a use case where the content is not removed, or when you need to integrate with a non-angular plugin that handles the DOM manipulation, then you need a way to stop its scopes watches and renders.

I agree that using such a feature would demand a more complex scope management from the developer using it, but still think it is a key feature to performance tuning.

I also came through this thread that came up with a solution. It works, but it's too "invasive". Currently, the best approach I came with is to create a directive that caches the raw HTML and remove, destroy the scope and recompiles it. But seems to be 'unnecessary' performance waste, as the framework could provide a way to easily bind/unbind the scope chain.

caiotoon avatar Feb 06 '13 14:02 caiotoon

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

btford avatar Aug 24 '13 00:08 btford

Just for the record, this hack can be useful too: Speeding up AngularJS's $digest loop

tachuris avatar Jul 15 '14 19:07 tachuris

Humm, This would be a really useful feature, I have tried using the above mechanism but I have a problem, due to the fact my 'emit/broadcast' is in a factory and my 'on' is in a controller.

  1. The data that is being bound is in a factory as are all the methods used to manipulate all the data.
  2. The edit controller is passed a reference to the above factory via a routeUI state change resolution.
  3. The data is retrieved in the state resolution ( resolve: { go get it...} ) this being a feature of routeUI, i.e. load the data then load the UI, so you don't get the blank page problem.
  4. So the $on() methods in the controller are not created until after the data has already loaded so I have no way way of 'suspending' bindings from the factory.

Because of load->change state order is strictly controlled I would have thought that angular would not start firing ng-change until after the state change has completed and everything is bound. It's almost as if it thinks there was data in there already which has then changed, interestingly it is only doing it for text fields.

Does this make any sense?

Anyway, I still think having a built in suspend/resume mechanism would be very useful and was surprised to see this request closed. For large complex UI's (albeit in the windows world) it is fairly common to:

suspend binding. does lots of stuff. resume binding. force repaint. (digest)

royjacob avatar Oct 07 '14 23:10 royjacob