简体   繁体   English

您在需要流的地方提供了一个无效的对象。 你可以提供一个 Observable、Promise、Array 或 Iterable

[英]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调用,因为internalDBexternalRequests调用的结果只是 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.

相关问题 TypeError:您在需要 stream 的地方提供了“未定义”。 部署angular时可以提供Observable、Promise、Array或Iterable - TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable when deploying angular 您在预期 stream 的位置提供了“未定义”。 在令牌拦截器中 - You provided 'undefined' where a stream was expected. in token interceptor 您提供了“未定义”,其中 Redux Observable 中预计会出现 stream - You provided `undefined` where a stream was expected in Redux Observable 错误:您在需要流的地方提供了“null” - Error: You provided 'null' where a stream was expected Angular 节点服务器返回您在预期 stream 的地方提供了“未定义” - Angular Node server returns You provided 'undefined' where a stream was expected Uncaught (in promise): TypeError: You provided using Observable.from() - Uncaught (in promise): TypeError: You provided using Observable.from() object 无效,应为 stream - Invalid object, expected stream 你能返回一个对象数组,每个 object 都包含一个来自 forkJoin 的 observable 吗? - Can you return an array of objects, with each object containing an observable from forkJoin? 您如何根据可观察 RxJ 的响应修改数组中的对象 - How do you modify object in array with response from observable RxJs Promise有“预期变量声明。”错误 - Promise has “Variable declaration expected.” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM