feat(rxjs): fix #830, monkey patch rxjs to make rxjs run in correct zone#843
feat(rxjs): fix #830, monkey patch rxjs to make rxjs run in correct zone#843mhevery merged 18 commits intoangular:masterfrom
Conversation
| return tearDownLogic.apply(this, arguments); | ||
| } | ||
| }; | ||
| return patchedTeadDownLogic; |
There was a problem hiding this comment.
Typo in 'patchedTeadDownLogic'.
| }); | ||
|
|
||
| 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.
Maybe we should call it zone-patch-rxjs to be consistent with zone-patch-cordova?
There was a problem hiding this comment.
Got it, I will change it.
| const unsubscribeSource = 'rxjs.Subscriber.unsubscribe'; | ||
|
|
||
| try { | ||
| rxjs = require('rxjs'); |
There was a problem hiding this comment.
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.
got it, I will try to organize the file into umd way.
| const _subscribe = this._subscribe; | ||
| if (_zone) { | ||
| this._subscribe = function() { | ||
| const subscriber = arguments.length > 0 ? arguments[0] : undefined; |
There was a problem hiding this comment.
referring to arguments is slower. Can we find another way to do this?
There was a problem hiding this comment.
yeah, I will use an array to get the object.
| 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.
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.createAnd // 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 |
mhevery
left a comment
There was a problem hiding this comment.
I think fixing the import/UMD is the only thing which is left.
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| let rxjs: any; |
There was a problem hiding this comment.
Why can't we do proper import {Rx} from 'rxjs/Rx';? I think that should work.
There was a problem hiding this comment.
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.
| */ | ||
|
|
||
| declare let define: any; | ||
| (function(root: any, factory: (Rx: any) => any) { |
There was a problem hiding this comment.
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.
I changed it into import * as Rx from 'rxjs/Rx'
| (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.
Out of these consts only nextSource seems to be used.
There was a problem hiding this comment.
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
rxjsrepository, ReactiveX/rxjs#2266, try to monkey patchrxjsto 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
Observableconstructor.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!