0

我正在尝试ngrx使用运算符集成缓存rxjs withLatestFrom。但得到一个错误:

You provided 'undefined' where a stream was expected.
You can provide an Observable, Promise, Array, or Iterable.

有人更正我的代码吗?

这是我的代码:

@Effect()
EffLoadCourse = this.actions.pipe(
  ofType(LoadCourse.TYPE),
  withLatestFrom(
    this.store.pipe(select(subscribes.getCourses)), //getting it from store
    (action: LoadCourse, courses: ModelCourse[]) => {
      // console.log('action is ', action, 'courses is', courses)
      return courses;
    }
  ),
  mergeMap((courses: ModelCourse[]) => {

    if (courses) { //if courses available just return it
      map((courses: ModelCourse[]) => (new LoadCourseSuccess(courses))),
        catchError(err => of(new LoadCourseFail(err)))
      return;
    }
    //only return on courses unavailability
    return this.courseService.getCourse().pipe(
      map((courses: ModelCourse[]) => (new LoadCourseSuccess(courses))),
      catchError(err => of(new LoadCourseFail(err)))
    )
  })
)

4

1 回答 1

1
   if(courses){ //if courses available just return it
                    map((courses:ModelCourse[]) => (new LoadCourseSuccess(courses))),
                    catchError(err => of(new LoadCourseFail(err)))
                    return;
                }

你没有返回一个动作,只是一个void

于 2019-05-08T16:21:17.610 回答