0

我有一个史诗:

export default function uploadImage(action$, store) {
  return action$.ofType(userActions.UPLOAD_IMAGE)
    .mergeMap(action => {
      ...
      RNFetchBlob.fs.readFile(uploadUri, 'base64').then(data => {
        firebaseRef.putString(data).then(snapshot => {
          console.log('Uploaded a blob or file!');
          return Observable.of(userActions.updateImageURL(snapshot.downloadURL)); //<----------
        })
      });
    })
};

但是,这You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.是有道理的。

我如何将回调包装在可观察对象中,以使史诗不会中断?

4

2 回答 2

2

除了 Maxime 的回答,在您的示例中,实际问题似乎是您并没有真正返回 Promise!您需要返回它或切换到对箭头使用隐式返回语法

export default function uploadImage(action$, store) {
  return action$
    .ofType(userActions.UPLOAD_IMAGE)
    .mergeMap(action => {
      return Observable // don't forget to return this chain!
        .fromPromise(RNFetchBlob.fs.readFile(uploadUri, 'base64'))
        .map(data => {
          firebaseRef.putString(data).then(snapshot => {
            console.log('Uploaded a blob or file!');
            return userActions.updateImageURL(snapshot.downloadURL);
          })
        });

这是一个很常见的错误,我们都经历过!

于 2017-04-20T20:08:32.883 回答
1

大概是这样的:

export default function uploadImage(action$, store) {
  return action$
    .ofType(userActions.UPLOAD_IMAGE)
    .mergeMap(action => {
      ...
      Observable
        .fromPromise(RNFetchBlob.fs.readFile(uploadUri, 'base64'))
        .map(data => {
          firebaseRef.putString(data).then(snapshot => {
            console.log('Uploaded a blob or file!');
            return userActions.updateImageURL(snapshot.downloadURL);
          })
        });
于 2017-04-20T08:11:17.543 回答