-
Notifications
You must be signed in to change notification settings - Fork 408
feat(rxjs): fix #830, monkey patch rxjs to make rxjs run in correct zone #843
Conversation
lib/rxjs/rxjs.ts
Outdated
return tearDownLogic.apply(this, arguments); | ||
} | ||
}; | ||
return patchedTeadDownLogic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in 'patchedTeadDownLogic'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mleibman, thanks!
gulpfile.js
Outdated
@@ -199,6 +199,14 @@ gulp.task('build/sync-test.js', ['compile-esm'], function(cb) { | |||
return generateScript('./lib/zone-spec/sync-test.ts', 'sync-test.js', false, cb); | |||
}); | |||
|
|||
gulp.task('build/rxjs.js', ['compile-esm'], function(cb) { | |||
return generateScript('./lib/rxjs/rxjs.ts', 'zone-rxjs.js', false, cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should call it zone-patch-rxjs
to be consistent with zone-patch-cordova
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I will change it.
lib/rxjs/rxjs.ts
Outdated
const unsubscribeSource = 'rxjs.Subscriber.unsubscribe'; | ||
|
||
try { | ||
rxjs = require('rxjs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require
statement will not work in browser.
So far the .js
files have been stand alone code which can execute in global context, this means that we can't rely on ES6 import
to get a hold of Rx
.
There is also the matter that we have to run the code at a specific time. We have to load Zone.js
first than Rx
and only than we can do Rx
patching but before the other code gets it.
I think the solution here is to package this file as umd
that way it can be used in both cases.
It would mean that at some point one would have to import it as: zone.js/rxjs-patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, I will try to organize the file into umd
way.
lib/rxjs/rxjs.ts
Outdated
const _subscribe = this._subscribe; | ||
if (_zone) { | ||
this._subscribe = function() { | ||
const subscriber = arguments.length > 0 ? arguments[0] : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
referring to arguments
is slower. Can we find another way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I will use an array to get the object.
lib/rxjs/rxjs.ts
Outdated
if (this.operator && _zone && _zone !== currentZone) { | ||
const call = this.operator.call; | ||
this.operator.call = function() { | ||
const subscriber = arguments.length > 0 ? arguments[0] : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't refer to arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I will use an array to get the object.
bf5b906
to
e90479a
Compare
@mhevery , I have modified the code based on your comment, and the travis build will be passed after #844 was merged, please review. And I found current patch only handle the // BoundCallbackObservable
static create<T>(func: Function,
selector: Function | void = undefined,
scheduler?: IScheduler): (...args: any[]) => Observable<T> {
return function(this: any, ...args: any[]): Observable<T> {
return new BoundCallbackObservable<T>(func, <any>selector, args, this, scheduler);
};
}
Observable.bindCallback = BoundCallbackObservable.create And // BoundCallbackObservable extends Observable
constructor(private callbackFunc: Function,
private selector: Function,
private args: any[],
private context: any,
private scheduler: IScheduler) {
super();
} And the I just added a new function and test cases to also patch the case like this, and I will continue to Finally, all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fixing the import/UMD is the only thing which is left.
test/rxjs/rxjs.spec.ts
Outdated
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
let rxjs: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we do proper import {Rx} from 'rxjs/Rx';
? I think that should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a way to make import
work in both
- npm run test (local build env)
- travis karma jasmine (dist env)
So we can use import * as Rx from 'rxjs/Rx'
in rxjs.ts
and rxjs.spec.ts
now, please review.
lib/rxjs/rxjs.ts
Outdated
*/ | ||
|
||
declare let define: any; | ||
(function(root: any, factory: (Rx: any) => any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing it this way we should use rollup umd function to build the UMD.
This should be replaced with simple import {RX} from 'rxjs'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it into import * as Rx from 'rxjs/Rx'
lib/rxjs/rxjs.ts
Outdated
(Rx: any) => { | ||
'use strict'; | ||
Zone.__load_patch('rxjs', (global: any, Zone: ZoneType, api: _ZonePrivate) => { | ||
const subscribeSource = 'rxjs.subscribe'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of these const
s only nextSource
seems to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified this one.
@misko, I just updated the
Please review. |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
1 similar comment
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
copy logic from @mhevery 's PR on
rxjs
repository, ReactiveX/rxjs#2266, try to monkey patchrxjs
to makerun in correct zone.
now the test can pass in Firefox 54 and node.
@mhevery , please review the idea is workable or not.
currently the risky part is
https://github.com/angular/zone.js/pull/843/files#diff-7dba82bf33d9e5b20f59836ce1601b82R25
To patch
Observable
constructor.I am not sure patch like this is ok or not. I will continue to find some other way to make sure
new Observable()
will use this patched version.If the idea is ok, I will add other test cases and make it work for other browsers.
Thank you!