Skip to content

Commit

Permalink
Merge branch 'master' into root
Browse files Browse the repository at this point in the history
  • Loading branch information
jayphelps authored Sep 15, 2016
2 parents 7d3dd70 + cd953b1 commit 9a4c306
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/tutorial/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ state.subscribe((state) => {
var prevState = {};
state.subscribe((state) => {
if (state.count !== prevState.count) {
document.querySelector('#count').innerHTML = state.count;
document.querySelector('#count').innerHTML = state.count;
}
if (state.inputValue !== prevState.inputValue) {
document.querySelector('#hello').innerHTML = 'Hello ' + state.inputValue;
Expand Down Expand Up @@ -144,7 +144,7 @@ class MyComponent extends ObservableComponent {
return (
<div>
<ul>
{this.state.messages.map(message => <li>{message.text}>/li>)}
{this.state.messages.map(message => <li>{message.text}</li>)}
</ul>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var exists = Rx.Observable.bindCallback(fs.exists);
exists('file.txt').subscribe(exists => console.log('Does file exist?', exists));

// From a callback (last argument is a callback)
// fs.exists = (pathA, pathB, cb(err, result))
// fs.rename = (pathA, pathB, cb(err, result))
var rename = Rx.Observable.bindNodeCallback(fs.rename);
rename('file.txt', 'else.txt').subscribe(() => console.log('Renamed!'));
```
Expand Down
54 changes: 54 additions & 0 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,60 @@ describe('Observable', () => {
source.subscribe();
});

it('should run unsubscription logic when an error is sent synchronously and subscribe is called with no arguments', () => {
let unsubscribeCalled = false;
const source = new Observable((subscriber: Rx.Subscriber<string>) => {
subscriber.error(0);
return () => {
unsubscribeCalled = true;
};
});

try {
source.subscribe();
} catch (e) {
// error'ing to an empty Observer re-throws, so catch and ignore it here.
}

expect(unsubscribeCalled).to.be.true;
});

it('should run unsubscription logic when an error is sent asynchronously and subscribe is called with no arguments', (done: MochaDone) => {
let unsubscribeCalled = false;
const source = new Observable((subscriber: Rx.Subscriber<string>) => {
const id = setInterval(() => {
try {
subscriber.error(0);
} catch (e) {
// asynchronously error'ing to an empty Observer re-throws, so catch and ignore it here.
}
}, 1);
return () => {
clearInterval(id);
unsubscribeCalled = true;
};
});

source.subscribe();

setTimeout(() => {
let err;
let errHappened = false;
try {
expect(unsubscribeCalled).to.be.true;
} catch (e) {
err = e;
errHappened = true;
} finally {
if (!errHappened) {
done();
} else {
done(err);
}
}
}, 100);
});

it('should return a Subscription that calls the unsubscribe function returned by the subscriber', () => {
let unsubscribeCalled = false;

Expand Down
2 changes: 1 addition & 1 deletion spec/operators/cache-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Rx from '../../dist/cjs/Rx';
import {expect} from 'chai';
declare const {hot, cold, time, expectObservable};
declare const {hot, cold, time, expectObservable, expectSubscriptions};

declare const rxTestScheduler: Rx.TestScheduler;

Expand Down
2 changes: 1 addition & 1 deletion src/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {

unsubscribe() {
const { done, xhr } = this;
if (!done && xhr && xhr.readyState !== 4) {
if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
xhr.abort();
}
super.unsubscribe();
Expand Down
6 changes: 3 additions & 3 deletions src/util/toSubscriber.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PartialObserver } from '../Observer';
import { Subscriber } from '../Subscriber';
import { $$rxSubscriber } from '../symbol/rxSubscriber';
import { PartialObserver, empty as emptyObserver } from '../Observer';

export function toSubscriber<T>(
nextOrObserver?: PartialObserver<T> | ((value: T) => void),
Expand All @@ -18,8 +18,8 @@ export function toSubscriber<T>(
}

if (!nextOrObserver && !error && !complete) {
return new Subscriber();
return new Subscriber(emptyObserver);
}

return new Subscriber(nextOrObserver, error, complete);
}
}

0 comments on commit 9a4c306

Please sign in to comment.