Skip to content

Commit

Permalink
Merge pull request #2317 from ReactiveX/master
Browse files Browse the repository at this point in the history
Bringing our `next` branch up to date
  • Loading branch information
jayphelps authored Jan 31, 2017
2 parents f8ba77d + a77821b commit 8af24dd
Show file tree
Hide file tree
Showing 29 changed files with 494 additions and 196 deletions.
2 changes: 0 additions & 2 deletions .lgtm

This file was deleted.

9 changes: 9 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ To reduce polymorphism and get better performance out of operators, some operato
<td><code>timeout(dueTime: number | Date, other?: Observable | Promise, scheduler?: Scheduler)</code></td>
<td><code>timeoutWith(due: number | Date, withObservable: ObservableInput, scheduler: Scheduler)</code></td>
</tr>
<tr>
<td rowspan="2"><code>sample</code></td>
<td><code>sample(interval: number, scheduler?: Scheduler)</code></td>
<td><code>sampleTime(interval: number, scheduler?: Scheduler)</code></td>
</tr>
<tr>
<td><code>sample(notifier: Observable)</code></td>
<td><code>sample(notifier: Observable)</code></td>
</tr>
</tbody>
</table>

Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,8 @@ npm install @reactivex/[email protected]
### CDN

For CDN, you can use [unpkg](https://unpkg.com/):

5.0.0-beta.1 - 5.0.0-beta.11:

https://unpkg.com/@reactivex/rxjs/dist/global/Rx.umd.js


5.0.0-beta.12 or higher:

https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js

https://unpkg.com/rxjs/bundles/Rx.min.js

#### Node.js Usage:

Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Which one you choose depends on the scenario. The normal **Observable** is great
## Controlling the flow
```js
// typing "hello world"
var input = Rx.Observable.fromEvent(document.querySelector('input'), 'keypress');
var input = Rx.Observable.fromEvent(document.querySelector('input'), 'input');

// Filter out target values less than 3 characters long
input.filter(event => event.target.value.length > 2)
Expand Down Expand Up @@ -79,7 +79,7 @@ input.takeUntil(stopStream)
## Producing values
```js
// typing "hello world"
var input = Rx.Observable.fromEvent(document.querySelector('input'), 'keypress');
var input = Rx.Observable.fromEvent(document.querySelector('input'), 'input');

// Pass on a new value
input.map(event => event.target.value)
Expand Down
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
},
"ghooks": {
"commit-msg": "node ./node_modules/validate-commit-msg/index.js",
"pre-commit": "npm run lint_staged"
}
},
"lint-staged": {
"*.@(js)": ["eslint --fix", "git add"],
"*.@(ts)": ["tslint --fix", "git add"]
"*.@(js)": [
"eslint --fix",
"git add"
],
"*.@(ts)": [
"tslint --fix",
"git add"
]
},
"scripts-info": {
"info": "List available script",
Expand All @@ -40,7 +42,6 @@
"lint_perf": "Run lint against performance test suite",
"lint_spec": "Run lint against test spec",
"lint_src": "Run lint against source",
"lint_staged": "Run lint against staged files",
"lint": "Run lint against everything",
"perf": "Run macro performance benchmark",
"perf_micro": "Run micro performance benchmark",
Expand All @@ -51,6 +52,8 @@
"watch": "Watch codebase, trigger compile when source code changes"
},
"scripts": {
"precommit": "lint-staged",
"commitmsg": "validate-commit-msg",
"info": "npm-scripts-info",
"build_all": "npm-run-all build_cjs build_global generate_packages",
"build_cjs": "npm-run-all clean_dist_cjs copy_src_cjs compile_dist_cjs",
Expand Down Expand Up @@ -82,7 +85,6 @@
"lint_perf": "eslint perf/",
"lint_spec": "tslint -c tslint.json \"spec/**/*.ts\"",
"lint_src": "tslint -c tslint.json \"src/**/*.ts\"",
"lint_staged": "lint-staged",
"lint": "npm-run-all --parallel lint_*",
"perf": "protractor protractor.conf.js",
"perf_micro": "node ./perf/micro/index.js",
Expand Down Expand Up @@ -157,12 +159,12 @@
"esdoc": "^0.4.7",
"eslint": "^3.8.0",
"fs-extra": "^0.30.0",
"ghooks": "^1.3.2",
"glob": "^7.0.3",
"gm": "^1.22.0",
"google-closure-compiler-js": "^20160916.0.0",
"gzip-size": "^3.0.0",
"http-server": "^0.9.0",
"husky": "^0.12.0",
"lint-staged": "^3.2.5",
"lodash": "^4.15.0",
"madge": "^1.4.3",
Expand All @@ -179,12 +181,14 @@
"promise": "^7.1.1",
"protractor": "^3.1.1",
"rollup": "0.36.3",
"rollup-plugin-inject": "^2.0.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rx": "latest",
"shx": "^0.1.4",
"sinon": "^2.0.0-pre",
"sinon-chai": "^2.8.0",
"source-map-support": "^0.4.0",
"tslib": "^1.0.0",
"tslib": "^1.5.0",
"tslint": "^4.2.0",
"typescript": "~2.0.6",
"typings": "^2.0.0",
Expand Down
24 changes: 24 additions & 0 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ describe('Observable', () => {
source.subscribe(function (x) { expect(x).to.equal(1); }, null, done);
});

it('should send errors thrown in the constructor down the error path', (done) => {
new Observable((observer) => {
throw new Error('this should be handled');
})
.subscribe({
error(err) {
expect(err).to.deep.equal(new Error('this should be handled'));
done();
}
});
});

describe('forEach', () => {
it('should iterate and return a Promise', (done: MochaDone) => {
const expected = [1, 2, 3];
Expand Down Expand Up @@ -582,6 +594,18 @@ describe('Observable.create', () => {
});
expect(called).to.be.true;
});

it('should send errors thrown in the passed function down the error path', (done) => {
Observable.create((observer) => {
throw new Error('this should be handled');
})
.subscribe({
error(err) {
expect(err).to.deep.equal(new Error('this should be handled'));
done();
}
});
});
});

/** @test {Observable} */
Expand Down
4 changes: 1 addition & 3 deletions spec/Subject-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ describe('Subject', () => {
expect(() => {
subject.subscribe(
function (x) { results3.push(x); },
function (e) { results3.push('E'); },
() => { results3.push('C'); }
);
}).to.throw();
}).to.throw(Rx.ObjectUnsubscribedError);

expect(results1).to.deep.equal([1, 2, 3, 4, 5]);
expect(results2).to.deep.equal([3, 4, 5]);
Expand Down
70 changes: 35 additions & 35 deletions spec/observables/fromEventPattern-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {expect} from 'chai';
import * as sinon from 'sinon';
import * as Rx from '../../dist/cjs/Rx';
import {noop} from '../../dist/cjs/util/noop';

declare const rxTestScheduler: Rx.TestScheduler;
declare const {hot, asDiagram, expectObservable, expectSubscriptions};
Expand All @@ -16,58 +18,56 @@ describe('Observable.fromEventPattern', () => {
.concat(Observable.never())
.subscribe(h);
}
const e1 = Observable.fromEventPattern(addHandler, () => void 0);
const e1 = Observable.fromEventPattern(addHandler);
const expected = '-----x-x---';
expectObservable(e1).toBe(expected, {x: 'ev'});
});

it('should call addHandler on subscription', () => {
let addHandlerCalledWith;
const addHandler = (h: any) => {
addHandlerCalledWith = h;
};
const addHandler = sinon.spy();
Observable.fromEventPattern(addHandler, noop).subscribe(noop);

const removeHandler = () => {
//noop
};
const call = addHandler.getCall(0);
expect(addHandler).calledOnce;
expect(call.args[0]).to.be.a('function');
});

Observable.fromEventPattern(addHandler, removeHandler)
.subscribe(() => {
//noop
});
it('should call removeHandler on unsubscription', () => {
const removeHandler = sinon.spy();

Observable.fromEventPattern(noop, removeHandler).subscribe(noop).unsubscribe();

expect(addHandlerCalledWith).to.be.a('function');
const call = removeHandler.getCall(0);
expect(removeHandler).calledOnce;
expect(call.args[0]).to.be.a('function');
});

it('should call removeHandler on unsubscription', () => {
let removeHandlerCalledWith;
const addHandler = () => {
//noop
};
const removeHandler = (h: any) => {
removeHandlerCalledWith = h;
};
it('should work without optional removeHandler', () => {
const addHandler: (h: Function) => any = sinon.spy();
Observable.fromEventPattern(addHandler).subscribe(noop);

const subscription = Observable.fromEventPattern(addHandler, removeHandler)
.subscribe(() => {
//noop
});
expect(addHandler).calledOnce;
});

subscription.unsubscribe();
it('should deliver return value of addHandler to removeHandler as signal', () => {
const expected = { signal: true};
const addHandler = () => expected;
const removeHandler = sinon.spy();
Observable.fromEventPattern(addHandler, removeHandler).subscribe(noop).unsubscribe();

expect(removeHandlerCalledWith).to.be.a('function');
const call = removeHandler.getCall(0);
expect(call).calledWith(sinon.match.any, expected);
});

it('should send errors in addHandler down the error path', () => {
it('should send errors in addHandler down the error path', (done: MochaDone) => {
Observable.fromEventPattern((h: any) => {
throw 'bad';
}, () => {
//noop
}).subscribe(() => {
//noop
}, (err: any) => {
expect(err).to.equal('bad');
});
}, noop).subscribe(
() => done(new Error('should not be called')),
(err: any) => {
expect(err).to.equal('bad');
done();
}, () => done(new Error('should not be called')));
});

it('should accept a selector that maps outgoing values', (done: MochaDone) => {
Expand Down
42 changes: 36 additions & 6 deletions spec/operators/catch-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const Observable = Rx.Observable;
/** @test {catch} */
describe('Observable.prototype.catch', () => {
asDiagram('catch')('should catch error and replace with a cold Observable', () => {
const e1 = hot('--a--b--# ');
const e2 = cold('-1-2-3-| ');
const expected = '--a--b---1-2-3-|)';
const e1 = hot('--a--b--# ');
const e2 = cold( '-1-2-3-|');
const expected = '--a--b---1-2-3-|';

const result = e1.catch((err: any) => e2);

Expand Down Expand Up @@ -83,6 +83,36 @@ describe('Observable.prototype.catch', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should unsubscribe from a caught hot caught observable when unsubscribed explicitly', () => {
const e1 = hot('-1-2-3-# ');
const e1subs = '^ ! ';
const e2 = hot('---3-4-5-6-7-8-9-|');
const e2subs = ' ^ ! ';
const expected = '-1-2-3-5-6-7- ';
const unsub = ' ! ';

const result = e1.catch(() => e2);

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should unsubscribe from a caught cold caught observable when unsubscribed explicitly', () => {
const e1 = hot('-1-2-3-# ');
const e1subs = '^ ! ';
const e2 = cold( '5-6-7-8-9-|');
const e2subs = ' ^ ! ';
const expected = '-1-2-3-5-6-7- ';
const unsub = ' ! ';

const result = e1.catch(() => e2);

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it('should catch error and replace it with a hot Observable', () => {
const e1 = hot('--a--b--# ');
const e1subs = '^ ! ';
Expand All @@ -101,8 +131,8 @@ describe('Observable.prototype.catch', () => {
'(caught) argument', () => {
const e1 = cold('--a--b--c--------| ');
const subs = ['^ ! ',
' ^ ! ',
' ^ !'];
' ^ ! ',
' ^ !'];
const expected = '--a--b----a--b----a--b--#';

let retries = 0;
Expand All @@ -128,7 +158,7 @@ describe('Observable.prototype.catch', () => {
'(caught) argument', () => {
const e1 = hot('--a--b--c----d---|');
const subs = ['^ ! ',
' ^ !'];
' ^ !'];
const expected = '--a--b-------d---|';

let retries = 0;
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/groupBy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ describe('Observable.prototype.groupBy', () => {
observer.complete();
}).groupBy(
(x: number) => x % 2,
(x: string) => x + '!'
(x: number) => x + '!'
);

expect(result instanceof MyCustomObservable).to.be.true;
Expand Down
25 changes: 25 additions & 0 deletions spec/operators/reduce-spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions, type};

Expand Down Expand Up @@ -65,6 +66,30 @@ describe('Observable.prototype.reduce', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should reduce with index without seed', (done: MochaDone) => {
const idx = [1, 2, 3, 4, 5];

Observable.range(0, 6).reduce((acc, value, index) => {
expect(idx.shift()).to.equal(index);
return value;
}).subscribe(null, null, () => {
expect(idx).to.be.empty;
done();
});
});

it('should reduce with index with seed', (done: MochaDone) => {
const idx = [0, 1, 2, 3, 4, 5];

Observable.range(0, 6).reduce((acc, value, index) => {
expect(idx.shift()).to.equal(index);
return value;
}, -1).subscribe(null, null, () => {
expect(idx).to.be.empty;
done();
});
});

it('should reduce with seed if source is empty', () => {
const e1 = hot('--a--^-------|');
const e1subs = '^ !';
Expand Down
Loading

0 comments on commit 8af24dd

Please sign in to comment.