[英]You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
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: externalRequests 返回一些形状:
{ _isScalar: false,
source:
{ _isScalar: false,
source: { _isScalar: false, array: [Object], scheduler: undefined },
operator: { project: [Object] } },
operator: undefined }
and can be .subscribe
'd to.并且可以
.subscribe
。
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: internalDB
,当.then
'd 直接从数据库返回正确的数据时,当包装在Rx.Observable.fromPromise
中时,返回以下形状:
{ _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: , 当
.subscribe
'd 直接返回如下内容时:
{ 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.
并收到以下形式的异常:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
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?总结一下:我将 promise 转换为 Observable 的正确方法是什么,以及如何合并/展平上述多个 observable?
As @martin mentioned you give functions to the zip
operator, not observables.正如@martin 提到的,您将函数提供给
zip
运算符,而不是 observables。
You need to call those functions with the needed params
for your code to work.您需要使用所需的
params
来调用这些函数,以使您的代码正常工作。
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)另外,我认为您不需要
mergeAll
调用,因为internalDB
和externalRequests
调用的结果只是 observables,而不是高阶 observables(包含 observables 的 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'通常是因为您从 'rxjs/operators' 导入了 zip
you should import zip from 'rxjs/observable'你应该从 'rxjs/observable' 导入 zip
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.