diff --git a/spec/operators/retry-spec.js b/spec/operators/retry-spec.js index 0d8ba8a5d3..40a5cdf2f0 100644 --- a/spec/operators/retry-spec.js +++ b/spec/operators/retry-spec.js @@ -6,7 +6,10 @@ describe('Observable.prototype.retry()', function () { it('should retry a number of times, without error, then complete', function (done) { var errors = 0; var retries = 2; - Observable.of(42) + Observable.create(function (observer) { + observer.next(42); + observer.complete(); + }) .map(function (x) { if ((errors += 1) < retries) { throw 'bad'; @@ -27,7 +30,10 @@ describe('Observable.prototype.retry()', function () { it('should retry a number of times, then call error handler', function (done) { var errors = 0; var retries = 2; - Observable.of(42) + Observable.create(function (observer) { + observer.next(42); + observer.complete(); + }) .map(function (x) { if ((errors += 1) < retries) { throw 'bad'; @@ -50,7 +56,10 @@ describe('Observable.prototype.retry()', function () { it('should retry until successful completion', function (done) { var errors = 0; var retries = 10; - Observable.of(42) + Observable.create(function (observer) { + observer.next(42); + observer.complete(); + }) .map(function (x) { if ((errors += 1) < retries) { throw 'bad'; diff --git a/src/observables/ScalarObservable.ts b/src/observables/ScalarObservable.ts index 473c620d4a..8e754b95f4 100644 --- a/src/observables/ScalarObservable.ts +++ b/src/observables/ScalarObservable.ts @@ -1,5 +1,9 @@ import Scheduler from '../Scheduler'; import Observable from '../Observable'; +import tryCatch from '../util/tryCatch'; +import { errorObject } from '../util/errorObject'; +import ErrorObservable from './ErrorObservable'; +import EmptyObservable from './EmptyObservable'; export default class ScalarObservable extends Observable { @@ -49,4 +53,13 @@ export default class ScalarObservable extends Observable { } } } + + map(project: (x: T, ix?: number) => R, thisArg?: any): Observable { + let result = tryCatch(project).call(thisArg || this, this.value, 0); + if (result === errorObject) { + return new ErrorObservable(errorObject.e); + } else { + return new ScalarObservable(project.call(thisArg || this, this.value, 0)); + } + } }