5

Our application uses sockets, we are using socket.io and its events are wrap with Observables.

In one area of our application we have a graph that updates every 10th of a second. The graph is drawn with D3 and draws directly without using angular.

We would like to disable change detection for the graph area completely and ensure that each socket response (Observable) does not trigger change detection anywhere in the application tree.

We tried using zone.runOutsideAngular, but we had to put it at the lower socket layer where we subscribe to the Observable that wraps socket.io...Although this worked, it runs ALL socket events outside angular. We need to run only the graphing events outside of angular's zone.

Ideally we need to use zones or something at the component level and only for the graphs, because other areas of the application do need change detection from socket events...

It is my understanding that any async operations such as socket events will trigger change detection.

Can we disable this at a higher level without having to touch lower level services?

What is the best approach for running specific socket.io events outside of angular's zone in order to avoid change detection in the whole application?

Any insight would be greatly appreciated.

Thibs
  • 8,058
  • 13
  • 54
  • 85
  • I too am very interested in this answer. If you know of a good resource to learn more, please post as the doc on change detection as it relates to sockets seemed a bit sparse. – JoelParke Apr 21 '17 at 17:13
  • Exact same situation here.. Working with stock data on charts, and adding runOutsideAngular doesn't really seem to work, the chrome debugger still shows its doing heavy lifting whenever the websocket receives some packages – DutchKevv Jun 17 '17 at 15:54
  • Similar issue using this package: https://github.com/afrad/angular2-websocket. I have also been playing with `ChangeDetectorRef` by detaching/re-attaching when updating/drawing a graph. – Taylor Aug 22 '17 at 15:55

0 Answers0