-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to RxJS 5.0.0-alpha.6 #21
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const Rx = require(`rx`) | ||
const Rx = require(`@reactivex/rxjs`) | ||
const superagent = require(`superagent`) | ||
|
||
function optionsToSuperagent({ | ||
|
@@ -71,24 +71,29 @@ 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 | ||
} | ||
|
||
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,14 +108,12 @@ function makeHTTPDriver({eager = false} = {eager: false}) { | |
.map(reqOptions => { | ||
let response$ = createResponse$(reqOptions) | ||
if (eager || reqOptions.eager) { | ||
response$ = response$.replay(null, 1) | ||
response$.connect() | ||
response$ = response$.publishReplay(null, 1).connect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha this shouldn't work, because connect() actually returns a Subscription, not an Observable. That's why in the original code the connect() was on a different line. |
||
return response$ | ||
} | ||
response$.request = reqOptions | ||
return response$ | ||
}) | ||
.replay(null, 1) | ||
response$$.connect() | ||
}).shareReplay(null, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shareReplay is replay().refCount(), which is different than replay() + connect(). I'd advise to keep the replay() + connect(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same line or separate like above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every tests fails switching to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be related to ReactiveX/rxjs#453, so you can revert it so tests pass. But I'm not particularly happy with this situation. Let's make tests pass and then later let's try using HTTP driver with RxJS Next in real apps to see if there is actually a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response$$ wth There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all tests fail? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All HTTP tests, the node tests pass, unless for whatever reason I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you send a commit using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return response$$ | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,12 +17,13 @@ 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( | ||
function onNext() { assert.fail(); }, | ||
function onError(err) { | ||
debugger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? :) |
||
assert.strictEqual(err.message, 'Observable of requests given to ' + | ||
'HTTP Driver must emit either URL strings or objects with ' + | ||
'parameters.' | ||
|
@@ -36,25 +36,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 +71,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 +94,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 +118,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$) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks actually like a proper solution IMO.