RxJS version: 6.0.0
Code to reproduce:
https://gist.github.com/wldcordeiro/db399052e7ee62a331c791b81325abb6
Expected behavior: It produces an Observable
Actual behavior:
TypeError: You provided 'function (observer) {
var client = null;
_promise2.default.all([_promise2.default.resolve().then(function () {
return require('aws-mqtt');
}), _promise2.default.resolve().then(function () {
return require('aws-sdk/global');
})]).then(function (_ref2) {
var _ref3 = (0, _slicedToArray3.default)(_ref2, 2),
AWSMqtt = _ref3[0],
config = _ref3[1].config;
config.update({
region: region,
credentials: credentials
});
client = AWSMqtt.connect({
WebSocket: window.WebSocket,
region: region,
endpoint: endpoint,
credentials: credentials,
connectTimeout: 30 * 1000
});
client.on('connect', function () {
client.subscribe('' + topic, { qos: 1 }, function (err) {
if (err) {
observer.error(err);
} else {
// Send back another observable to be subscribed to
observer.next(listener(client));
}
});
});
client.on('error', function (err) {
return observer.error(err);
});
});
return function () {
client && client.end();
observer.complete();
};
}' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
20 | // listened to for messages
21 | export default (topic, endpoint, { region, credentials }) => {
> 22 | return from(observer => {
23 | let client = null
24 | Promise.all([import('aws-mqtt'), import('aws-sdk/global')]).then(
25 | ([AWSMqtt, { config }]) => {
at Object.<anonymous>.exports.subscribeTo (node_modules/rxjs/src/internal/util/subscribeTo.ts:37:11)
at from (node_modules/rxjs/src/internal/observable/from.ts:20:27)
at Object.<anonymous>.exports.default (src/aws/iot.js:22:9)
at Object.<anonymous> (src/aws/iot.test.js:83:2)
So from the looks of it from() doesn't recreate the same usage as Observable.create() did in RxJS 5.x and doesn't accept functions, but this isn't mentioned in the migration documentation from what I can tell. What would be my migration path here?
What prompted you to replace Observable.create with from? In 6.0.0, you should still be using Observable.create for this.
Ah, I got the sense I needed to change this from this section. https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#observable-classes
All observable classes (https://github.com/ReactiveX/rxjs/tree/5.5.8/src/observable) have been removed from v6, in favor of existing or new operators that perform the same operations as the class methods.
From that I got the idea that Observable.create was going the way of the dodo along with Observable.of, Observable.throw, etc.
I see. It does say that ArrayObservable.create(myArray) can be replaced with from(myArray), but Observable.create is still the 'low-level' method for creating an observable.
When you need an observable that cannot be composed using one of the in-built factory functions, Observable.create is still what you'll need to use.
Sounds good I thought it had either been turned into from() or a barecreate() (this seemed logical based on all the other methods being removed from Observable.)
I've re-read the migration guide to make sure that I'm not giving dodgy advice.
Observable.create is not deprecated, but one of the examples in the guide uses new Observable instead of the calling the static create.
Most of the observable implementations now seem to do that, too, so if you want to replace Observable.create with something, new Observable would be the way to go.
One (essentially cosmetic) difference with new Observable is that it's a little clearer, as the type parameter is specified against the class - instead of the observer parameter to the static create function's callback.
The type declaration for Observable.create has never been ideal and it's possible the switch to new Observable is related to that.
@wldcordeiro FYI, from Ben Lesh:
Yeah, people should be using
new Observable, however, in cases where they want to create an observable withcallorapply, then they'd needcreate... for now.
Awesome, I had pinged him about it too but didn't get a response but it's good to get clarification, it'd be cool to see this in the migration document so others aren't confused. 馃槃
@wldcordeiro A PR would be welcome, I guess.
I still recommend new Observable where you don't need to use apply or call to create the observable.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I see. It does say that
ArrayObservable.create(myArray)can be replaced withfrom(myArray), butObservable.createis still the 'low-level' method for creating an observable.When you need an observable that cannot be composed using one of the in-built factory functions,
Observable.createis still what you'll need to use.