Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 31fc127

Browse files
JiaLiPassionmhevery
authored andcommitted
feat(build): Upgrade to TypeScript 2.9 and rxjs6 (#1122)
This includes a migration to TS2.9, and a migration to RxJS 6 (which is required for TS2.9 support).
1 parent 9c96904 commit 31fc127

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+669
-734
lines changed

karma-base.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function(config) {
1717
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false},
1818
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
1919
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false},
20+
{pattern: 'node_modules/core-js/**/*.js', included: false, watched: false},
2021
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false},
2122
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
2223
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},

lib/rxjs/rxjs-fake-async.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Scheduler} from 'rxjs/Scheduler';
10-
import {asap} from 'rxjs/scheduler/asap';
11-
import {async} from 'rxjs/scheduler/async';
9+
import {asapScheduler, asyncScheduler, Scheduler} from 'rxjs';
1210

1311
Zone.__load_patch('rxjs.Scheduler.now', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
1412
api.patchMethod(Scheduler, 'now', (delegate: Function) => (self: any, args: any[]) => {
1513
return Date.now.apply(self, args);
1614
});
17-
api.patchMethod(async, 'now', (delegate: Function) => (self: any, args: any[]) => {
15+
api.patchMethod(asyncScheduler, 'now', (delegate: Function) => (self: any, args: any[]) => {
1816
return Date.now.apply(self, args);
1917
});
20-
api.patchMethod(asap, 'now', (delegate: Function) => (self: any, args: any[]) => {
18+
api.patchMethod(asapScheduler, 'now', (delegate: Function) => (self: any, args: any[]) => {
2119
return Date.now.apply(self, args);
2220
});
2321
});

lib/rxjs/rxjs.ts

+52-226
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,20 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import 'rxjs/add/observable/bindCallback';
10-
import 'rxjs/add/observable/bindNodeCallback';
11-
import 'rxjs/add/observable/defer';
12-
import 'rxjs/add/observable/forkJoin';
13-
import 'rxjs/add/observable/fromEventPattern';
14-
import 'rxjs/add/operator/multicast';
9+
import {Observable, Subscriber, Subscription} from 'rxjs';
1510

16-
import {Observable} from 'rxjs/Observable';
17-
import {asap} from 'rxjs/scheduler/asap';
18-
import {Subscriber} from 'rxjs/Subscriber';
19-
import {Subscription} from 'rxjs/Subscription';
20-
import {rxSubscriber} from 'rxjs/symbol/rxSubscriber';
21-
22-
(Zone as any).__load_patch('rxjs', (global: any, Zone: ZoneType) => {
11+
(Zone as any).__load_patch('rxjs', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
2312
const symbol: (symbolString: string) => string = (Zone as any).__symbol__;
2413
const nextSource = 'rxjs.Subscriber.next';
2514
const errorSource = 'rxjs.Subscriber.error';
2615
const completeSource = 'rxjs.Subscriber.complete';
2716

2817
const ObjectDefineProperties = Object.defineProperties;
2918

30-
const empty = {
31-
closed: true,
32-
next(value: any): void{},
33-
error(err: any): void {
34-
throw err;
35-
},
36-
complete(): void {}
37-
};
38-
39-
function toSubscriber<T>(
40-
nextOrObserver?: any, error?: (error: any) => void, complete?: () => void): Subscriber<T> {
41-
if (nextOrObserver) {
42-
if (nextOrObserver instanceof Subscriber) {
43-
return (<Subscriber<T>>nextOrObserver);
44-
}
45-
46-
if (nextOrObserver[rxSubscriber]) {
47-
return nextOrObserver[rxSubscriber]();
48-
}
49-
}
50-
51-
if (!nextOrObserver && !error && !complete) {
52-
return new Subscriber(empty);
53-
}
54-
55-
return new Subscriber(nextOrObserver, error, complete);
56-
}
57-
5819
const patchObservable = function() {
5920
const ObservablePrototype: any = Observable.prototype;
60-
const symbolSubscribe = symbol('subscribe');
6121
const _symbolSubscribe = symbol('_subscribe');
6222
const _subscribe = ObservablePrototype[_symbolSubscribe] = ObservablePrototype._subscribe;
63-
const subscribe = ObservablePrototype[symbolSubscribe] = ObservablePrototype.subscribe;
6423

6524
ObjectDefineProperties(Observable.prototype, {
6625
_zone: {value: null, writable: true, configurable: true},
@@ -89,30 +48,58 @@ import {rxSubscriber} from 'rxjs/symbol/rxSubscriber';
8948
},
9049
set: function(this: Observable<any>, subscribe: any) {
9150
(this as any)._zone = Zone.current;
92-
(this as any)._zoneSubscribe = subscribe;
51+
(this as any)._zoneSubscribe = function() {
52+
if (this._zone && this._zone !== Zone.current) {
53+
const tearDown = this._zone.run(subscribe, this, arguments);
54+
if (tearDown && typeof tearDown === 'function') {
55+
const zone = this._zone;
56+
return function() {
57+
if (zone !== Zone.current) {
58+
return zone.run(tearDown, this, arguments);
59+
}
60+
return tearDown.apply(this, arguments);
61+
};
62+
}
63+
return tearDown;
64+
}
65+
return subscribe.apply(this, arguments);
66+
};
9367
}
9468
},
95-
subscribe: {
96-
writable: true,
97-
configurable: true,
98-
value: function(this: Observable<any>, observerOrNext: any, error: any, complete: any) {
99-
// Only grab a zone if we Zone exists and it is different from the current zone.
100-
const _zone = (this as any)._zone;
101-
if (_zone && _zone !== Zone.current) {
102-
// Current Zone is different from the intended zone.
103-
// Restore the zone before invoking the subscribe callback.
104-
return _zone.run(subscribe, this, [toSubscriber(observerOrNext, error, complete)]);
105-
}
106-
return subscribe.call(this, observerOrNext, error, complete);
69+
subjectFactory: {
70+
get: function() {
71+
return (this as any)._zoneSubjectFactory;
72+
},
73+
set: function(factory: any) {
74+
const zone = this._zone;
75+
this._zoneSubjectFactory = function() {
76+
if (zone && zone !== Zone.current) {
77+
return zone.run(factory, this, arguments);
78+
}
79+
return factory.apply(this, arguments);
80+
};
10781
}
10882
}
10983
});
11084
};
11185

86+
api.patchMethod(Observable.prototype, 'lift', (delegate: any) => (self: any, args: any[]) => {
87+
const observable: any = delegate.apply(self, args);
88+
if (observable.operator) {
89+
observable.operator._zone = Zone.current;
90+
api.patchMethod(
91+
observable.operator, 'call',
92+
(operatorDelegate: any) => (operatorSelf: any, operatorArgs: any[]) => {
93+
if (operatorSelf._zone && operatorSelf._zone !== Zone.current) {
94+
return operatorSelf._zone.run(operatorDelegate, operatorSelf, operatorArgs);
95+
}
96+
return operatorDelegate.apply(operatorSelf, operatorArgs);
97+
});
98+
}
99+
return observable;
100+
});
101+
112102
const patchSubscription = function() {
113-
const unsubscribeSymbol = symbol('unsubscribe');
114-
const unsubscribe = (Subscription.prototype as any)[unsubscribeSymbol] =
115-
Subscription.prototype.unsubscribe;
116103
ObjectDefineProperties(Subscription.prototype, {
117104
_zone: {value: null, writable: true, configurable: true},
118105
_zoneUnsubscribe: {value: null, writable: true, configurable: true},
@@ -126,22 +113,12 @@ import {rxSubscriber} from 'rxjs/symbol/rxSubscriber';
126113
},
127114
set: function(this: Subscription, unsubscribe: any) {
128115
(this as any)._zone = Zone.current;
129-
(this as any)._zoneUnsubscribe = unsubscribe;
130-
}
131-
},
132-
unsubscribe: {
133-
writable: true,
134-
configurable: true,
135-
value: function(this: Subscription) {
136-
// Only grab a zone if we Zone exists and it is different from the current zone.
137-
const _zone: Zone = (this as any)._zone;
138-
if (_zone && _zone !== Zone.current) {
139-
// Current Zone is different from the intended zone.
140-
// Restore the zone before invoking the subscribe callback.
141-
_zone.run(unsubscribe, this);
142-
} else {
143-
unsubscribe.apply(this);
144-
}
116+
(this as any)._zoneUnsubscribe = function() {
117+
if (this._zone && this._zone !== Zone.current) {
118+
return this._zone.run(unsubscribe, this, arguments);
119+
}
120+
return unsubscribe.apply(this, arguments);
121+
};
145122
}
146123
}
147124
});
@@ -205,158 +182,7 @@ import {rxSubscriber} from 'rxjs/symbol/rxSubscriber';
205182
};
206183
};
207184

208-
const patchObservableInstance = function(observable: any) {
209-
observable._zone = Zone.current;
210-
};
211-
212-
const patchObservableFactoryCreator = function(obj: any, factoryName: string) {
213-
const symbolFactory: string = symbol(factoryName);
214-
if (obj[symbolFactory]) {
215-
return;
216-
}
217-
const factoryCreator: any = obj[symbolFactory] = obj[factoryName];
218-
if (!factoryCreator) {
219-
return;
220-
}
221-
obj[factoryName] = function() {
222-
const factory: any = factoryCreator.apply(this, arguments);
223-
return function() {
224-
const observable = factory.apply(this, arguments);
225-
patchObservableInstance(observable);
226-
return observable;
227-
};
228-
};
229-
};
230-
231-
const patchObservableFactory = function(obj: any, factoryName: string) {
232-
const symbolFactory: string = symbol(factoryName);
233-
if (obj[symbolFactory]) {
234-
return;
235-
}
236-
const factory: any = obj[symbolFactory] = obj[factoryName];
237-
if (!factory) {
238-
return;
239-
}
240-
obj[factoryName] = function() {
241-
const observable = factory.apply(this, arguments);
242-
patchObservableInstance(observable);
243-
return observable;
244-
};
245-
};
246-
247-
const patchObservableFactoryArgs = function(obj: any, factoryName: string) {
248-
const symbolFactory: string = symbol(factoryName);
249-
if (obj[symbolFactory]) {
250-
return;
251-
}
252-
const factory: any = obj[symbolFactory] = obj[factoryName];
253-
if (!factory) {
254-
return;
255-
}
256-
obj[factoryName] = function() {
257-
const initZone = Zone.current;
258-
const args = Array.prototype.slice.call(arguments);
259-
for (let i = 0; i < args.length; i++) {
260-
const arg = args[i];
261-
if (typeof arg === 'function') {
262-
args[i] = function() {
263-
const argArgs = Array.prototype.slice.call(arguments);
264-
const runningZone = Zone.current;
265-
if (initZone && runningZone && initZone !== runningZone) {
266-
return initZone.run(arg, this, argArgs);
267-
} else {
268-
return arg.apply(this, argArgs);
269-
}
270-
};
271-
}
272-
}
273-
274-
const observable = factory.apply(this, args);
275-
patchObservableInstance(observable);
276-
return observable;
277-
};
278-
};
279-
280-
const patchMulticast = function() {
281-
const obj: any = Observable.prototype;
282-
const factoryName: string = 'multicast';
283-
const symbolFactory: string = symbol(factoryName);
284-
if (obj[symbolFactory]) {
285-
return;
286-
}
287-
const factory: any = obj[symbolFactory] = obj[factoryName];
288-
if (!factory) {
289-
return;
290-
}
291-
obj[factoryName] = function() {
292-
const _zone: any = Zone.current;
293-
const args = Array.prototype.slice.call(arguments);
294-
let subjectOrSubjectFactory: any = args.length > 0 ? args[0] : undefined;
295-
if (typeof subjectOrSubjectFactory !== 'function') {
296-
const originalFactory: any = subjectOrSubjectFactory;
297-
subjectOrSubjectFactory = function() {
298-
return originalFactory;
299-
};
300-
}
301-
args[0] = function() {
302-
let subject: any;
303-
if (_zone && _zone !== Zone.current) {
304-
subject = _zone.run(subjectOrSubjectFactory, this, arguments);
305-
} else {
306-
subject = subjectOrSubjectFactory.apply(this, arguments);
307-
}
308-
if (subject && _zone) {
309-
subject._zone = _zone;
310-
}
311-
return subject;
312-
};
313-
const observable = factory.apply(this, args);
314-
patchObservableInstance(observable);
315-
return observable;
316-
};
317-
};
318-
319-
const patchImmediate = function(asap: any) {
320-
if (!asap) {
321-
return;
322-
}
323-
324-
const scheduleSymbol = symbol('scheduleSymbol');
325-
const zoneSymbol = symbol('zone');
326-
if (asap[scheduleSymbol]) {
327-
return;
328-
}
329-
330-
const schedule = asap[scheduleSymbol] = asap.schedule;
331-
asap.schedule = function() {
332-
const args = Array.prototype.slice.call(arguments);
333-
const work = args.length > 0 ? args[0] : undefined;
334-
const delay = args.length > 1 ? args[1] : 0;
335-
const state = (args.length > 2 ? args[2] : undefined) || {};
336-
state[zoneSymbol] = Zone.current;
337-
338-
const patchedWork = function() {
339-
const workArgs = Array.prototype.slice.call(arguments);
340-
const action = workArgs.length > 0 ? workArgs[0] : undefined;
341-
const scheduleZone = action && action[zoneSymbol];
342-
if (scheduleZone && scheduleZone !== Zone.current) {
343-
return scheduleZone.runGuarded(work, this, arguments);
344-
} else {
345-
return work.apply(this, arguments);
346-
}
347-
};
348-
return schedule.call(this, patchedWork, delay, state);
349-
};
350-
};
351-
352185
patchObservable();
353186
patchSubscription();
354187
patchSubscriber();
355-
patchObservableFactoryCreator(Observable, 'bindCallback');
356-
patchObservableFactoryCreator(Observable, 'bindNodeCallback');
357-
patchObservableFactory(Observable, 'defer');
358-
patchObservableFactory(Observable, 'forkJoin');
359-
patchObservableFactoryArgs(Observable, 'fromEventPattern');
360-
patchMulticast();
361-
patchImmediate(asap);
362188
});

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"clang-format": "^1.2.3",
6767
"concurrently": "^2.2.0",
6868
"conventional-changelog": "^1.1.7",
69+
"core-js": "^2.5.7",
6970
"es6-promise": "^3.0.2",
7071
"google-closure-compiler": "^20170409.0.0",
7172
"gulp": "^3.8.11",
@@ -93,13 +94,13 @@
9394
"phantomjs": "^2.1.7",
9495
"promises-aplus-tests": "^2.1.2",
9596
"pump": "^1.0.1",
96-
"rxjs": "^5.5.3",
97+
"rxjs": "^6.2.1",
9798
"selenium-webdriver": "^3.4.0",
9899
"systemjs": "^0.19.37",
99100
"ts-loader": "^0.6.0",
100101
"tslint": "^4.1.1",
101102
"tslint-eslint-rules": "^3.1.0",
102-
"typescript": "2.5.2",
103+
"typescript": "2.9.2",
103104
"vrsource-tslint-rules": "^4.0.0",
104105
"webdriver-manager": "^12.0.6",
105106
"webdriverio": "^4.8.0",

test/browser_entry_point.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import 'core-js/features/set';
10+
import 'core-js/features/map';
911
// List all tests here:
1012
import './common_tests';
1113
import './browser/browser.spec';

0 commit comments

Comments
 (0)