diff --git a/package.json b/package.json index c185924..69608a6 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,10 @@ "superagent": "1.4.0" }, "peerDependencies": { - "@cycle/core": "5.x.x" + "@reactivex/rxjs": "5.0.0-alpha.6" }, "devDependencies": { - "@cycle/core": "5.0.x", - "rx": "4.0.6", + "@reactivex/rxjs": "5.0.0-alpha.6", "babel": "5.8.23", "babelify": "6.3.0", "body-parser": "1.14.1", diff --git a/src/http-driver.js b/src/http-driver.js index debbfb0..75f52e1 100644 --- a/src/http-driver.js +++ b/src/http-driver.js @@ -1,4 +1,4 @@ -const Rx = require(`rx`) +const Rx = require(`@reactivex/rxjs`) const superagent = require(`superagent`) function optionsToSuperagent({ @@ -71,9 +71,14 @@ function createResponse$(reqOptions) { if (typeof reqOptions === `string`) { request = urlToSuperagent(reqOptions) } else if (typeof reqOptions === `object`) { - request = optionsToSuperagent(reqOptions) + try { + request = optionsToSuperagent(reqOptions) + } catch (err) { + observer.error(err) + return () => {} // noop + } } else { - observer.onError(new Error(`Observable of requests given to HTTP ` + + observer.error(new Error(`Observable of requests given to HTTP ` + `Driver must emit either URL strings or objects with parameters.`)) return () => {} // noop } @@ -81,14 +86,14 @@ function createResponse$(reqOptions) { try { request.end((err, res) => { if (err) { - observer.onError(err) + observer.error(err) } else { - observer.onNext(res) - observer.onCompleted() + observer.next(res) + observer.complete() } }) } catch (err) { - observer.onError(err) + observer.error(err) } return function onDispose() { @@ -103,13 +108,13 @@ function makeHTTPDriver({eager = false} = {eager: false}) { .map(reqOptions => { let response$ = createResponse$(reqOptions) if (eager || reqOptions.eager) { - response$ = response$.replay(null, 1) + response$ = response$.publishReplay(1) response$.connect() + return response$ } response$.request = reqOptions return response$ - }) - .replay(null, 1) + }).publishReplay(1) response$$.connect() return response$$ } diff --git a/test/common.js b/test/common.js index 3f2d94b..52f8d70 100644 --- a/test/common.js +++ b/test/common.js @@ -2,8 +2,7 @@ /* global describe, it */ var assert = require('assert'); var src = require('../lib/index'); -var Cycle = require('@cycle/core'); -var Rx = require('rx'); +var Rx = require('@reactivex/rxjs'); var makeHTTPDriver = src.makeHTTPDriver; function run(uri) { @@ -18,7 +17,7 @@ function run(uri) { describe('HTTP Driver', function () { it('should throw when request stream emits neither string nor object', function(done) { - var request$ = Rx.Observable.just(123); + var request$ = Rx.Observable.of(123); var httpDriver = makeHTTPDriver(); var response$$ = httpDriver(request$); response$$.mergeAll().subscribe( @@ -36,25 +35,26 @@ function run(uri) { it('should throw when given options object without url string', function(done) { - var request$ = Rx.Observable.just({method: 'post'}); + var request$ = Rx.Observable.of({method: 'post'}); var httpDriver = makeHTTPDriver(); var response$$ = httpDriver(request$); - response$$.mergeAll().subscribe( - function onNext() { assert.fail(); }, - function onError(err) { - assert.strictEqual( - err.message, 'Please provide a `url` property in the request ' + - 'options.' - ); - done(); - } - ); + response$$.mergeAll() + .subscribe( + function onNext() { assert.fail(); }, + function onError(err) { + assert.strictEqual( + err.message, 'Please provide a `url` property in the request ' + + 'options.' + ); + done(); + } + ); } ); it('should return response metastream when given a simple URL string', function(done) { - var request$ = Rx.Observable.just(uri + '/hello'); + var request$ = Rx.Observable.of(uri + '/hello'); var httpDriver = makeHTTPDriver(); var response$$ = httpDriver(request$); response$$.subscribe(function(response$) { @@ -70,7 +70,7 @@ function run(uri) { it('should return response metastream when given simple options obj', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/pet', method: 'POST', send: {name: 'Woof', species: 'Dog'} @@ -93,7 +93,7 @@ function run(uri) { it('should return response metastream when given another options obj', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/querystring', method: 'GET', query: {foo: 102030, bar: 'Pub'} @@ -117,7 +117,7 @@ function run(uri) { it('should send 500 server errors to response$ onError', function(done) { - var request$ = Rx.Observable.just(uri + '/error'); + var request$ = Rx.Observable.of(uri + '/error'); var httpDriver = makeHTTPDriver(); var response$$ = httpDriver(request$); response$$.subscribe(function(response$) { diff --git a/test/node.js b/test/node.js index 943d3d3..73e6a4f 100644 --- a/test/node.js +++ b/test/node.js @@ -7,8 +7,7 @@ require('./common')(uri); // Node.js specific ============================================================ var assert = require('assert'); -var Cycle = require('@cycle/core'); -var Rx = require('rx'); +var Rx = require('@reactivex/rxjs'); var src = require('../lib/index'); var makeHTTPDriver = src.makeHTTPDriver; var globalSandbox = require('./support/global'); @@ -16,7 +15,7 @@ var globalSandbox = require('./support/global'); describe('HTTP Driver in Node.js', function () { it('should auto-execute HTTP request when factory gets eager = true', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/pet', method: 'POST', send: {name: 'Woof', species: 'Dog'} @@ -35,7 +34,7 @@ describe('HTTP Driver in Node.js', function () { it('should not auto-execute HTTP request by default', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/pet', method: 'POST', send: {name: 'Woof', species: 'Dog'} @@ -52,7 +51,7 @@ describe('HTTP Driver in Node.js', function () { it('should auto-execute HTTP request if the request has eager = true', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/pet', method: 'POST', send: {name: 'Woof', species: 'Dog'}, @@ -72,7 +71,7 @@ describe('HTTP Driver in Node.js', function () { it('should not auto-execute HTTP request when factory gets eager = false', function(done) { - var request$ = Rx.Observable.just({ + var request$ = Rx.Observable.of({ url: uri + '/pet', method: 'POST', send: {name: 'Woof', species: 'Dog'}