Skip to content

Commit

Permalink
Merge branch 'master' into groupby-subject-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh authored Oct 19, 2016
2 parents 359ec8a + 8ebee66 commit ebd88f1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ By contributing or commenting on issues in this repository, whether you've read
### ES6 via npm

```sh
npm install rxjs-es
npm install rxjs
```

To import the entire core set of functionality:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
"copy_src_cjs": "mkdirp ./dist/cjs/src && shx cp -r ./src/* ./dist/cjs/src",
"copy_src_es6": "mkdirp ./dist/es6/src && shx cp -r ./src/* ./dist/es6/src",
"commit": "git-cz",
"compile_dist_cjs": "tsc typings/globals/es6-shim/index.d.ts ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_dist_cjs": "tsc ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_dist_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_dist_es6_for_docs": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts ./dist/es6/src/MiscJSDoc.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"cover": "shx rm -rf dist/cjs && tsc typings/globals/es6-shim/index.d.ts src/Rx.ts src/add/observable/of.ts -m commonjs --outDir dist/cjs --sourceMap --target ES5 -d && nyc --reporter=lcov --reporter=html --exclude=spec/support/**/* --exclude=spec-js/**/* --exclude=node_modules mocha --opts spec/support/default.opts spec-js",
"cover": "shx rm -rf dist/cjs && tsc src/Rx.ts src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --outDir dist/cjs --sourceMap --target ES5 -d && nyc --reporter=lcov --reporter=html --exclude=spec/support/**/* --exclude=spec-js/**/* --exclude=node_modules mocha --opts spec/support/default.opts spec-js",
"decision_tree_widget": "cd doc/decision-tree-widget && npm run build && cd ../..",
"doctoc": "doctoc CONTRIBUTING.md",
"generate_packages": "node .make-packages.js",
Expand Down
63 changes: 63 additions & 0 deletions spec/observables/IteratorObservable-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import {queue} from '../../dist/cjs/scheduler/queue';
import {IteratorObservable} from '../../dist/cjs/observable/IteratorObservable';

declare const expectObservable;
Expand Down Expand Up @@ -46,6 +47,68 @@ describe('IteratorObservable', () => {
);
});

it('should finalize generators if the subscription ends', () => {
const iterator = {
finalized: false,
next() {
return { value: 'duck', done: false };
},
return() {
this.finalized = true;
}
};

const iterable = {
[Rx.Symbol.iterator]() {
return iterator;
}
};

const results = [];

IteratorObservable.create(iterable)
.take(3)
.subscribe(
x => results.push(x),
null,
() => results.push('GOOSE!')
);

expect(results).to.deep.equal(['duck', 'duck', 'duck', 'GOOSE!']);
expect(iterator.finalized).to.be.true;
});

it('should finalize generators if the subscription and it is scheduled', () => {
const iterator = {
finalized: false,
next() {
return { value: 'duck', done: false };
},
return() {
this.finalized = true;
}
};

const iterable = {
[Rx.Symbol.iterator]() {
return iterator;
}
};

const results = [];

IteratorObservable.create(iterable, queue)
.take(3)
.subscribe(
x => results.push(x),
null,
() => results.push('GOOSE!')
);

expect(results).to.deep.equal(['duck', 'duck', 'duck', 'GOOSE!']);
expect(iterator.finalized).to.be.true;
});

it('should emit members of an array iterator on a particular scheduler', () => {
const source = IteratorObservable.create(
[10, 20, 30, 40],
Expand Down
10 changes: 9 additions & 1 deletion spec/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
"allowJs": true,
"target": "es5",
"module": "commonjs",
"outDir": "../spec-js"
"outDir": "../spec-js",
"lib": [
"es5",
"es2015.core",
"es2015.collection",
"es2015.iterable",
"es2015.promise",
"dom"
]
},
"formatCodeOptions": {
"indentSize": 2,
Expand Down
4 changes: 2 additions & 2 deletions src/Subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export class Subject<T> extends Observable<T> implements ISubscription {
return new AnonymousSubject<T>(destination, source);
};

lift<T, R>(operator: Operator<T, R>): Observable<T> {
lift<R>(operator: Operator<T, R>): Observable<T> {
const subject = new AnonymousSubject(this, this);
subject.operator = operator;
subject.operator = <any>operator;
return <any>subject;
}

Expand Down
6 changes: 6 additions & 0 deletions src/observable/IteratorObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class IteratorObservable<T> extends Observable<T> {
state.index = index + 1;

if (subscriber.closed) {
if (typeof iterator.return === 'function') {
iterator.return();
}
return;
}

Expand Down Expand Up @@ -71,6 +74,9 @@ export class IteratorObservable<T> extends Observable<T> {
subscriber.next(result.value);
}
if (subscriber.closed) {
if (typeof iterator.return === 'function') {
iterator.return();
}
break;
}
} while (true);
Expand Down
2 changes: 1 addition & 1 deletion src/operator/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { TeardownLogic } from '../Subscription';
* @owner Observable
*/
/* tslint:disable:max-line-length */
export function _do<T>(next: (x: T) => void, error?: (e: any) => void, complete?: (this: Observable<T>) => void): Observable<T>;
export function _do<T>(this: Observable<T>, next: (x: T) => void, error?: (e: any) => void, complete?: () => void): Observable<T>;
export function _do<T>(this: Observable<T>, observer: PartialObserver<T>): Observable<T>;
/* tslint:disable:max-line-length */
export function _do<T>(this: Observable<T>, nextOrObserver?: PartialObserver<T> | ((x: T) => void),
Expand Down
5 changes: 1 addition & 4 deletions typings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"sinon-chai": "registry:npm/sinon-chai#2.8.0+20160310030142"
},
"globalDevDependencies": {
"mocha": "registry:env/mocha#2.2.5+20160723033700"
},
"globalDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504"
"mocha": "registry:env/mocha#2.2.5+20160926180742"
}
}

0 comments on commit ebd88f1

Please sign in to comment.