You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
I was looking at the ScopeScheduler test to figure out how ScopeScheduler should be used, but I'm not sure I understand the test either, so I'm still not sure I understand how to use ScopeScheduler.
I assume that if ScopeScheduler is used with .observeOn(), the code in the subscriber's onNext function will effectively be passed to Scope.$apply() thus ensuring the onNext logic is followed by a $digest() so potentially-relevant watcher callbacks are run. Based on that assumption, I'd write a naive test like this:
varinjector=angular.injector(['ng','rx']);varscope=injector.get('$rootScope').$new();scope.$watch('testProperty',function(val){start();ok(true,'testProperty watcher fired');equal(val,42,'testProperty should match value emitted by observable');});Rx.Observable.return(42).observeOn(newRx.ScopeScheduler(scope)).subscribe(function(value){scope.testProperty=value;});expect(2);
I think this would prove the ScopeScheduler caused the watcher to fire and that the testProperty contains the expected value. (This test passes.)
But in the current test... the two watchers on testProperty - $watch() and $toObservable() - and the throttle and the assignment in the tap and the testProperty2 and the commented-out test that fails... These all have me confused and thinking I must be missing something. What was the test trying to prove beyond my basic test above?
The current test only seems to prove that the onNext function is invoked - ok(true). We've no idea if a digest is actually triggered by the scheduler and no idea if the watchers see new values that might have been set inside the onNext. But again, maybe I'm completely missing some understanding of the intended usage of ScopeScheduler.
//ok(scope.testProperty2 === 2); -- Don't know why this doesn't work.
I think the scope.testProperty = 2 assignment inside the tap won't be noticed by Angular until after the ok(scope.testProperty2 === 2) test is run on the ScopeScheduler. This is because an Angular $apply()first evaluates it's expression/function arg - in this case the subscribe()'s onNext function containing the failing ok() - and then Angular calls $rootScope.$digest() which fires all the watchers. So the first watcher's invocation that should be assigning 2 to scope.testProperty2 doesn't fire until after the code where you test scope.testProperty2 === 2, hence scope.testProperty2 is still 1 and that test fails.
Also I noticed the implementation of ScopeScheduler contains scheduleNow, scheduleRelative, and scheduleAbsolute functions that are passed to the base Scheduler implementation. I barely even understand what those are for, but does this test attempt to exercise them somehow? How and when would I make use of an immediate, relative or absolute ScopeScheduler?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I was looking at the ScopeScheduler test to figure out how ScopeScheduler should be used, but I'm not sure I understand the test either, so I'm still not sure I understand how to use ScopeScheduler.
I assume that if ScopeScheduler is used with
.observeOn()
, the code in the subscriber's onNext function will effectively be passed toScope.$apply()
thus ensuring the onNext logic is followed by a$digest()
so potentially-relevant watcher callbacks are run. Based on that assumption, I'd write a naive test like this:I think this would prove the ScopeScheduler caused the watcher to fire and that the testProperty contains the expected value. (This test passes.)
But in the current test... the two watchers on
testProperty
-$watch()
and$toObservable()
- and the throttle and the assignment in the tap and thetestProperty2
and the commented-out test that fails... These all have me confused and thinking I must be missing something. What was the test trying to prove beyond my basic test above?The current test only seems to prove that the onNext function is invoked -
ok(true)
. We've no idea if a digest is actually triggered by the scheduler and no idea if the watchers see new values that might have been set inside the onNext. But again, maybe I'm completely missing some understanding of the intended usage of ScopeScheduler.As for the commented-out line :
I think the
scope.testProperty = 2
assignment inside the tap won't be noticed by Angular until after theok(scope.testProperty2 === 2)
test is run on the ScopeScheduler. This is because an Angular$apply()
first evaluates it's expression/function arg - in this case thesubscribe()
's onNext function containing the failingok()
- and then Angular calls$rootScope.$digest()
which fires all the watchers. So the first watcher's invocation that should be assigning 2 toscope.testProperty2
doesn't fire until after the code where you testscope.testProperty2 === 2
, hencescope.testProperty2
is still 1 and that test fails.Also I noticed the implementation of ScopeScheduler contains scheduleNow, scheduleRelative, and scheduleAbsolute functions that are passed to the base Scheduler implementation. I barely even understand what those are for, but does this test attempt to exercise them somehow? How and when would I make use of an immediate, relative or absolute ScopeScheduler?
The text was updated successfully, but these errors were encountered: