我正在尝试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)))
)
})
)