Reactive-Extensions / rx.angular.js

AngularJS Bindings for RxJS
Other
827 stars 89 forks source link

DigestObserver does not check root scope $$phase before digesting #141

Open sirbarrence opened 8 years ago

sirbarrence commented 8 years ago

When using DigestObserver via scope.$digestObservable() it's possible to trigger

Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.5.5/$rootScope/inprog?p0=%24apply
    at angular.js:68
    at beginPhase (angular.js:17587)
    at Scope.$digest (angular.js:17025)
    at Scope.$apply (angular.js:17337)
    at DigestObserver.next (rx.angular.js:566)
    at DigestObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (rx.all.js:1752)
    at DigestObserver.tryCatcher (rx.all.js:63)
    at AutoDetachObserverPrototype.next (rx.all.js:11781)
    at AutoDetachObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (rx.all.js:1752)
    at InnerObserver.next (rx.all.js:5582)(anonymous function)

if the the scope that $digestObservables() was invoked on was not digesting but the root scope was digesting.

This is because unlike all the other rx.angular code that tries to invoke Scope.$apply, DigestObserver only checks $scope.$$phase and not $scope.$root.$$phase to decide whether to invoke the property setter immediately or to schedule it with Scope.$apply().

Angular: 1.5.5 rx-angular: 1.1.3

sirbarrence commented 8 years ago

Will resubmit pull request to fix this once #144 is merged so the build will pass.