refactor(async): replace RxJS with RxNext

Closes #3110
Closes #4201
This commit is contained in:
vsavkin 2015-09-11 15:38:09 -07:00 committed by Jeff Cross
parent 7b3161a229
commit 16bf335a4a
25 changed files with 61 additions and 96 deletions

View File

@ -50,7 +50,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
createTypeDefinitionFile.typeDefinitions = [ createTypeDefinitionFile.typeDefinitions = [
{ {
id: 'angular2/angular2', id: 'angular2/angular2',
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'], references: ['../es6-promise/es6-promise.d.ts'],
modules: { modules: {
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'}, 'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'},
'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'}, 'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'},

View File

@ -359,8 +359,8 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
function getType(sourceFile, type) { function getType(sourceFile, type) {
var text = getText(sourceFile, type); var text = getText(sourceFile, type);
while (text.indexOf(".") >= 0) { while (text.indexOf(".") >= 0) {
// Keep namespaced symbols in Rx // Keep namespaced symbols in RxNext
if (text.match(/^\s*Rx\./)) break; if (text.match(/^\s*RxNext\./)) break;
// handle the case List<thing.stuff> -> List<stuff> // handle the case List<thing.stuff> -> List<stuff>
text = text.replace(/([^.<]*)\.([^>]*)/, "$2"); text = text.replace(/([^.<]*)\.([^>]*)/, "$2");
} }

View File

@ -1017,11 +1017,13 @@ gulp.task('!build.js.cjs', function() {
var bundleConfig = { var bundleConfig = {
paths: {"*": "dist/js/prod/es5/*.js", "rx": "node_modules/rx/dist/rx.js"}, paths: {
"*": "dist/js/prod/es5/*.js"
},
meta: { meta: {
'angular2/src/router/route_definition': {format: 'cjs'}, 'angular2/src/router/route_definition': {
// auto-detection fails to detect properly here - https://github.com/systemjs/builder/issues/123 format: 'cjs'
'rx': {format: 'cjs'} }
} }
}; };
@ -1072,7 +1074,10 @@ gulp.task('!bundle.js.min', ['build.js.prod'], function() {
// development build // development build
gulp.task('!bundle.js.dev', ['build.js.dev'], function() { gulp.task('!bundle.js.dev', ['build.js.dev'], function() {
var devBundleConfig = merge(true, bundleConfig); var devBundleConfig = merge(true, bundleConfig);
devBundleConfig.paths = merge(true, devBundleConfig.paths, {"*": "dist/js/dev/es5/*.js"}); devBundleConfig.paths =
merge(true, devBundleConfig.paths, {
"*": "dist/js/dev/es5/*.js"
});
return bundler.bundle( return bundler.bundle(
devBundleConfig, devBundleConfig,
'angular2/angular2', 'angular2/angular2',
@ -1150,7 +1155,7 @@ gulp.task('!bundle.js.prod.deps', ['!bundle.js.prod'], function() {
'angular2.js' 'angular2.js'
), ),
bundler.modify( bundler.modify(
['node_modules/reflect-metadata/Reflect.js', 'node_modules/rx/dist/rx.lite.js', 'dist/build/http.js'], ['node_modules/reflect-metadata/Reflect.js', 'dist/build/http.js'],
'http.js' 'http.js'
)).pipe(gulp.dest('dist/js/bundle')); )).pipe(gulp.dest('dist/js/bundle'));
}); });
@ -1162,7 +1167,7 @@ gulp.task('!bundle.js.min.deps', ['!bundle.js.min'], function() {
'angular2.min.js' 'angular2.min.js'
), ),
bundler.modify( bundler.modify(
['node_modules/reflect-metadata/Reflect.js', 'node_modules/rx/dist/rx.lite.js','dist/build/http.min.js'], ['node_modules/reflect-metadata/Reflect.js', 'dist/build/http.min.js'],
'http.min.js' 'http.min.js'
)) ))
.pipe(uglify()) .pipe(uglify())
@ -1179,9 +1184,9 @@ var JS_DEV_DEPS = [
// Splice in RX license if rx is in the bundle. // Splice in RX license if rx is in the bundle.
function insertRXLicense(source) { function insertRXLicense(source) {
var n = source.indexOf('System.register("rx"'); var n = source.indexOf('System.register("@reactivex/rxjs/dist/cjs/Subject"');
if (n >= 0) { if (n >= 0) {
var rxLicense = licenseWrap('node_modules/rx/license.txt'); var rxLicense = licenseWrap('node_modules/@reactivex/rxjs/LICENSE.txt');
return source.slice(0, n) + rxLicense + source.slice(n); return source.slice(0, n) + rxLicense + source.slice(n);
} else { } else {
return source; return source;

View File

@ -21,7 +21,7 @@ module.exports = function(config) {
// Including systemjs because it defines `__eval`, which produces correct stack traces. // Including systemjs because it defines `__eval`, which produces correct stack traces.
'modules/angular2/src/test_lib/shims_for_IE.js', 'modules/angular2/src/test_lib/shims_for_IE.js',
'node_modules/systemjs/dist/system.src.js', 'node_modules/systemjs/dist/system.src.js',
{pattern: 'node_modules/rx/dist/rx.js', included: false, watched: false, served: true}, {pattern: 'node_modules/@reactivex/rxjs/dist/cjs/**', included: false, watched: false, served: true},
'node_modules/reflect-metadata/Reflect.js', 'node_modules/reflect-metadata/Reflect.js',
'tools/build/file2modulename.js', 'tools/build/file2modulename.js',
'test-main.js', 'test-main.js',

View File

@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"traceur": "<%= packageJson.dependencies.traceur %>", "traceur": "<%= packageJson.dependencies.traceur %>",
"reflect-metadata": "<%= packageJson.dependencies['reflect-metadata'] %>", "reflect-metadata": "<%= packageJson.dependencies['reflect-metadata'] %>",
"rx": "<%= packageJson.dependencies['rx'] %>", "@reactivex/rxjs": "<%= packageJson.dependencies['@reactivex/rxjs'] %>",
"zone.js": "<%= packageJson.dependencies['zone.js'] %>" "zone.js": "<%= packageJson.dependencies['zone.js'] %>"
}, },
"devDependencies": <%= JSON.stringify(packageJson.defaultDevDependencies) %>, "devDependencies": <%= JSON.stringify(packageJson.defaultDevDependencies) %>,

View File

@ -1,6 +1,7 @@
///<reference path="../../../typings/tsd.d.ts" /> ///<reference path="../../../typings/tsd.d.ts" />
import {global, isPresent} from 'angular2/src/core/facade/lang'; import {global, isPresent} from 'angular2/src/core/facade/lang';
import * as Rx from 'rx'; // TODO(jeffbcross): use ES6 import once typings are available
var Subject = require('@reactivex/rxjs/dist/cjs/Subject');
export {Promise}; export {Promise};
@ -75,7 +76,7 @@ export class ObservableWrapper {
static isObservable(obs: any): boolean { return obs instanceof Observable; } static isObservable(obs: any): boolean { return obs instanceof Observable; }
static dispose(subscription: any) { subscription.dispose(); } static dispose(subscription: any) { subscription.unsubscribe(); }
static callNext(emitter: EventEmitter, value: any) { emitter.next(value); } static callNext(emitter: EventEmitter, value: any) { emitter.next(value); }
@ -128,30 +129,19 @@ export class Observable {
* Once a reference implementation of the spec is available, switch to it. * Once a reference implementation of the spec is available, switch to it.
*/ */
export class EventEmitter extends Observable { export class EventEmitter extends Observable {
_subject: Rx.Subject<any> = new Rx.Subject<any>(); _subject = new Subject();
_immediateScheduler = (<any>Rx.Scheduler).immediate;
observer(generator: any): Rx.IDisposable { observer(generator: any): any {
return this._subject.observeOn(this._immediateScheduler) return this._subject.subscribe((value) => { setTimeout(() => generator.next(value)); },
.subscribe((value) => { setTimeout(() => generator.next(value)); },
(error) => generator.throw ? generator.throw(error) : null, (error) => generator.throw ? generator.throw(error) : null,
() => generator.return ? generator.return () : null); () => generator.return ? generator.return () : null);
} }
toRx(): Rx.Observable<any> { return this._subject; } toRx(): any { return this; }
/** next(value: any) { this._subject.next(value); }
* Emits a `value`.
*/
next(value: any) { this._subject.onNext(value); }
/** throw(error: any) { this._subject.error(error); }
* Emits an `error`.
*/
throw(error: any) { this._subject.onError(error); }
/** return (value?: any) { this._subject.complete(); }
* Closes the stream.
*/
return (value?: any) { this._subject.onCompleted(); }
} }

View File

@ -1,5 +1,3 @@
/// <reference path="../../typings/rx/rx.d.ts" />
import { import {
ReadyStates, ReadyStates,
RequestModesOpts, RequestModesOpts,

View File

@ -9,7 +9,7 @@
"repository": <%= JSON.stringify(packageJson.repository) %>, "repository": <%= JSON.stringify(packageJson.repository) %>,
"dependencies": { "dependencies": {
"angular2": "<%= packageJson.version %>", "angular2": "<%= packageJson.version %>",
"rx": "<%= packageJson.dependencies['rx'] %>", "@reactivex/rxjs": "<%= packageJson.dependencies['@reactivex/rxjs'] %>",
"reflect-metadata": "<%= packageJson.dependencies['reflect-metadata'] %>", "reflect-metadata": "<%= packageJson.dependencies['reflect-metadata'] %>",
"traceur": "<%= packageJson.dependencies['traceur'] %>" "traceur": "<%= packageJson.dependencies['traceur'] %>"
}, },

View File

@ -1,5 +1,4 @@
import {EventEmitter} from 'angular2/src/core/facade/async'; import {EventEmitter} from 'angular2/src/core/facade/async';
import * as Rx from 'rx';
import {ListWrapper} from 'angular2/src/core/facade/collection'; import {ListWrapper} from 'angular2/src/core/facade/collection';
export class MockEventEmitter extends EventEmitter { export class MockEventEmitter extends EventEmitter {
@ -7,7 +6,7 @@ export class MockEventEmitter extends EventEmitter {
constructor() { super(); } constructor() { super(); }
observer(generator: any): Rx.IDisposable { observer(generator: any): any {
this._nextFns.push(generator.next); this._nextFns.push(generator.next);
return new MockDisposable(); return new MockDisposable();
} }
@ -17,6 +16,7 @@ export class MockEventEmitter extends EventEmitter {
} }
} }
class MockDisposable implements Rx.IDisposable { class MockDisposable {
dispose(): void {} isUnsubscribed: boolean = false;
unsubscribe(): void {}
} }

View File

@ -17,14 +17,6 @@
"node/node.d.ts": { "node/node.d.ts": {
"commit": "51738fdf1643d269067861b405e87503b7479236" "commit": "51738fdf1643d269067861b405e87503b7479236"
}, },
"rx/rx.d.ts": {
"commit": "3882d337bb0808cde9fe4c08012508a48c135482"
},
"rx/rx-lite.d.ts": {
"commit": "3882d337bb0808cde9fe4c08012508a48c135482"
},
"selenium-webdriver/selenium-webdriver.d.ts": { "selenium-webdriver/selenium-webdriver.d.ts": {
"commit": "be0b6b394f77a59e192ad7cfec18078706e44db5" "commit": "be0b6b394f77a59e192ad7cfec18078706e44db5"

View File

@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"angular2": "<%= packageJson.version %>", "angular2": "<%= packageJson.version %>",
"traceur": "<%= packageJson.dependencies.traceur %>", "traceur": "<%= packageJson.dependencies.traceur %>",
"rx": "<%= packageJson.dependencies['rx'] %>", "@reactivex/rxjs": "<%= packageJson.dependencies['@reactivex/rxjs'] %>",
"zone.js": "<%= packageJson.dependencies['zone.js'] %>" "zone.js": "<%= packageJson.dependencies['zone.js'] %>"
}, },
"devDependencies": <%= JSON.stringify(packageJson.defaultDevDependencies) %> "devDependencies": <%= JSON.stringify(packageJson.defaultDevDependencies) %>

View File

@ -1,5 +1,3 @@
/// <reference path="../../../angular2/typings/rx/rx.d.ts" />
import {bootstrap} from 'angular2/bootstrap'; import {bootstrap} from 'angular2/bootstrap';
import {HTTP_BINDINGS} from 'angular2/http'; import {HTTP_BINDINGS} from 'angular2/http';
import {HttpCmp} from './http_comp'; import {HttpCmp} from './http_comp';

View File

@ -1,5 +1,3 @@
/// <reference path="../../../angular2/typings/rx/rx.d.ts" />
import {bootstrap} from 'angular2/bootstrap'; import {bootstrap} from 'angular2/bootstrap';
import {JSONP_BINDINGS} from 'angular2/http'; import {JSONP_BINDINGS} from 'angular2/http';
import {JsonpCmp} from './jsonp_comp'; import {JsonpCmp} from './jsonp_comp';

View File

@ -4,10 +4,7 @@ importScripts("b64.js");
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': 'examples/src/web_workers/images/rx.js'
}
}); });
System.import("examples/src/web_workers/images/background_index") System.import("examples/src/web_workers/images/background_index")

View File

@ -2,10 +2,7 @@ $SCRIPTS$
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': 'examples/src/web_workers/kitchen_sink/rx.js'
}
}); });
System.import("examples/src/web_workers/kitchen_sink/background_index") System.import("examples/src/web_workers/kitchen_sink/background_index")

View File

@ -1,10 +1,9 @@
$SCRIPTS$ $SCRIPTS$
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {'rx': 'examples/src/web_workers/message_broker/rx.js'} });
});
System.import("examples/src/web_workers/message_broker/background_index") System.import("examples/src/web_workers/message_broker/background_index")
.then( .then(

View File

@ -2,10 +2,7 @@ $SCRIPTS$
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': 'examples/src/web_workers/todo/rx.js'
}
}); });
System.import("examples/src/web_workers/todo/background_index") System.import("examples/src/web_workers/todo/background_index")

View File

@ -1,5 +1,8 @@
{ {
"dependencies": { "dependencies": {
"@reactivex/rxjs": {
"version": "0.0.0-prealpha.3"
},
"angular": { "angular": {
"version": "1.3.5" "version": "1.3.5"
}, },

5
npm-shrinkwrap.json generated
View File

@ -2,6 +2,11 @@
"name": "angular", "name": "angular",
"version": "2.0.0-alpha.37", "version": "2.0.0-alpha.37",
"dependencies": { "dependencies": {
"@reactivex/rxjs": {
"version": "0.0.0-prealpha.3",
"from": "@reactivex/rxjs@0.0.0-prealpha.3",
"resolved": "https://registry.npmjs.org/@reactivex/rxjs/-/rxjs-0.0.0-prealpha.3.tgz"
},
"angular": { "angular": {
"version": "1.3.5", "version": "1.3.5",
"from": "https://registry.npmjs.org/angular/-/angular-1.3.5.tgz", "from": "https://registry.npmjs.org/angular/-/angular-1.3.5.tgz",

View File

@ -28,8 +28,8 @@
"test": "gulp test.all.js && gulp test.all.dart" "test": "gulp test.all.js && gulp test.all.dart"
}, },
"dependencies": { "dependencies": {
"@reactivex/rxjs": "0.0.0-prealpha.3",
"reflect-metadata": "0.1.1", "reflect-metadata": "0.1.1",
"rx": "2.5.1",
"zone.js": "0.5.4" "zone.js": "0.5.4"
}, },
"devDependencies": { "devDependencies": {

View File

@ -15,7 +15,7 @@ System.config({
'angular2/*': 'dist/js/dev/es5/angular2/*.js', 'angular2/*': 'dist/js/dev/es5/angular2/*.js',
'angular2_material/*': 'dist/js/dev/es5/angular2_material/*.js', 'angular2_material/*': 'dist/js/dev/es5/angular2_material/*.js',
'rtts_assert/*': 'dist/js/dev/es5/rtts_assert/*.js', 'rtts_assert/*': 'dist/js/dev/es5/rtts_assert/*.js',
'rx': 'node_modules/rx/dist/rx.js' '@reactivex/rxjs/*': 'node_modules/@reactivex/rxjs/*.js'
} }
}); });

View File

@ -5,14 +5,9 @@
<script src="Reflect.js" type="text/javascript"></script> <script src="Reflect.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var filename = '@@FILENAME_NO_EXT'; var filename = '@@FILENAME_NO_EXT';
var parent = filename.split('/');
parent = parent.splice(0, parent.length-1).join('/');
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': parent + '/rx.js'
}
}); });
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console)); System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
</script> </script>

View File

@ -6,14 +6,9 @@
<script src="Reflect.js" type="text/javascript"></script> <script src="Reflect.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var filename = '@@FILENAME_NO_EXT'; var filename = '@@FILENAME_NO_EXT';
var parent = filename.split('/');
parent = parent.splice(0, parent.length-1).join('/');
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': parent + '/rx.js'
}
}); });
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console)); System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
</script> </script>

View File

@ -7,14 +7,9 @@
<script src="Reflect.js" type="text/javascript"></script> <script src="Reflect.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var filename = '@@FILENAME_NO_EXT'; var filename = '@@FILENAME_NO_EXT';
var parent = filename.split('/');
parent = parent.splice(0, parent.length-1).join('/');
System.config({ System.config({
baseURL: '/', baseURL: '/',
defaultJSExtensions: true, defaultJSExtensions: true
paths: {
'rx': parent + '/rx.js'
}
}); });
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console)); System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
</script> </script>

View File

@ -84,6 +84,8 @@ module.exports = function makeBrowserTree(options, destinationPath) {
destDir: '/' destDir: '/'
}); });
var rxJs = new Funnel('node_modules/@reactivex', {include: ['**/**'], destDir: '/@reactivex'});
var es5ModulesTree = new Funnel('modules', { var es5ModulesTree = new Funnel('modules', {
include: ['**/**'], include: ['**/**'],
exclude: ['**/*.cjs', 'angular1_router/**', 'benchmarks/e2e_test/**'], exclude: ['**/*.cjs', 'angular1_router/**', 'benchmarks/e2e_test/**'],
@ -139,7 +141,6 @@ module.exports = function makeBrowserTree(options, destinationPath) {
'node_modules/zone.js/dist/zone-microtask.js', 'node_modules/zone.js/dist/zone-microtask.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/systemjs/dist/system.src.js', 'node_modules/systemjs/dist/system.src.js',
'node_modules/rx/dist/rx.js',
'node_modules/base64-js/lib/b64.js', 'node_modules/base64-js/lib/b64.js',
'node_modules/reflect-metadata/Reflect.js', 'node_modules/reflect-metadata/Reflect.js',
'node_modules/es6-shim/es6-shim.js' 'node_modules/es6-shim/es6-shim.js'
@ -208,8 +209,8 @@ module.exports = function makeBrowserTree(options, destinationPath) {
htmlTree = mergeTrees([htmlTree, scripts, polymer, react]); htmlTree = mergeTrees([htmlTree, scripts, polymer, react]);
es5Tree = mergeTrees([es5Tree, htmlTree, assetsTree]); es5Tree = mergeTrees([es5Tree, htmlTree, assetsTree, rxJs]);
es6Tree = mergeTrees([es6Tree, htmlTree, assetsTree]); es6Tree = mergeTrees([es6Tree, htmlTree, assetsTree, rxJs]);
var mergedTree = mergeTrees([stew.mv(es6Tree, '/es6'), stew.mv(es5Tree, '/es5')]); var mergedTree = mergeTrees([stew.mv(es6Tree, '/es6'), stew.mv(es5Tree, '/es5')]);