admin管理员组文章数量:1287919
Say I have the following function references:
const externalRequests = (params) => Rx.Observable.zip(
externalApi1(params),
externalApi2(params)
)
and
const internalDB = (params) => Rx.Observable.fromPromise(getStuffFromDB(params)
externalRequests returns something of the shape:
{ _isScalar: false,
source:
{ _isScalar: false,
source: { _isScalar: false, array: [Object], scheduler: undefined },
operator: { project: [Object] } },
operator: undefined }
and can be .subscribe
'd to.
internalDB
, when .then
'd directly returns the right data from the database, and when wrapped in Rx.Observable.fromPromise
as above, returns something of the shape:
{ _p:
{ handle: 115,
type: 'promise',
className: 'Object',
constructorFunction: { ref: 122 },
protoObject: { ref: 123 },
prototypeObject: { ref: 1 },
status: 'pending',
promiseValue: { ref: 1 },
properties: [],
internalProperties: [ [Object], [Object] ],
text: '#<Promise>' },
_s: {} }
, which, when .subscribe
'd directly returns something like so:
{ isStopped: false,
observer:
{ isStopped: false,
_onNext: [Function: val],
_onError: [Function: val],
_onCompleted: [Function: val] },
m:
{ isDisposed: false,
current: { isDisposed: false, current: null } } }
Say I now want to flatten all of this into a single stream: so I write something like:
Rx.Observable.zip(externalRequests, internalDB).mergeAll().subsribe(() => console.log('potato'))
And receive an exception of the form:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
To summarize: What is the correct way for me to cast my promise as an Observable, and how do I merge/flatten multiple observables as above?
Say I have the following function references:
const externalRequests = (params) => Rx.Observable.zip(
externalApi1(params),
externalApi2(params)
)
and
const internalDB = (params) => Rx.Observable.fromPromise(getStuffFromDB(params)
externalRequests returns something of the shape:
{ _isScalar: false,
source:
{ _isScalar: false,
source: { _isScalar: false, array: [Object], scheduler: undefined },
operator: { project: [Object] } },
operator: undefined }
and can be .subscribe
'd to.
internalDB
, when .then
'd directly returns the right data from the database, and when wrapped in Rx.Observable.fromPromise
as above, returns something of the shape:
{ _p:
{ handle: 115,
type: 'promise',
className: 'Object',
constructorFunction: { ref: 122 },
protoObject: { ref: 123 },
prototypeObject: { ref: 1 },
status: 'pending',
promiseValue: { ref: 1 },
properties: [],
internalProperties: [ [Object], [Object] ],
text: '#<Promise>' },
_s: {} }
, which, when .subscribe
'd directly returns something like so:
{ isStopped: false,
observer:
{ isStopped: false,
_onNext: [Function: val],
_onError: [Function: val],
_onCompleted: [Function: val] },
m:
{ isDisposed: false,
current: { isDisposed: false, current: null } } }
Say I now want to flatten all of this into a single stream: so I write something like:
Rx.Observable.zip(externalRequests, internalDB).mergeAll().subsribe(() => console.log('potato'))
And receive an exception of the form:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
To summarize: What is the correct way for me to cast my promise as an Observable, and how do I merge/flatten multiple observables as above?
Share Improve this question asked Jun 19, 2017 at 14:28 Abraham PAbraham P 15.5k13 gold badges63 silver badges130 bronze badges 1-
1
My guess is that the problem is in
internalDB
which is a method returning an Observable. It's not an Observable itself sozip()
can't subscribe to a method. Anyway if you don't provide stackoverflow./help/mcve it's hard to tell... – martin Commented Jun 19, 2017 at 14:34
3 Answers
Reset to default 3As @martin mentioned you give functions to the zip
operator, not observables.
You need to call those functions with the needed params
for your code to work.
Also, I don't think you need the mergeAll
call, as the result of internalDB
and externalRequests
calls are only observables, not higher order observables (observables containing observables)
Rx.Observable
// ▼ you need to call the functions in order to get their observables
.zip(externalRequests(params), internalDB(params))
.subscribe(() => console.log('potato'))
my mistake to import file like this...
import {loginEpic} from "./Epic";
and i just correct this like...
import loginEpic from "./Epic";
usually it's because you imported zip from 'rxjs/operators'
you should import zip from 'rxjs/observable'
本文标签:
版权声明:本文标题:javascript - You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Itera 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741272660a2369552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论