Angular @Effect监听指定Action类型的实现原理
发布日期:2021-06-30 14:34:34 浏览次数:2 分类:技术文章

本文共 965 字,大约阅读时间需要 3 分钟。

Ngrx里action的职责就是express unique events & intents.

源代码:

@Effect()  searchBookICanbeAnyName$: Observable
= this.actions$.pipe( ofType(bookManage.SEARCH), // 监听bookManager.SEARCH action? debounceTime(300), mergeMap((action: bookManage.SearchAction) => {
const nextSearch$ = this.actions$.pipe(ofType(bookManage.SEARCH), skip(1)); return this.service.searchBooks(action.payload).pipe( takeUntil(nextSearch$), // If successful, dispatch success action with result map((data: BookResult) => ({
type: bookManage.SEARCH_COMPLETE, payload: data.items})), // If request fails, dispatch failed action catchError(() => of({
type: bookManage.SEARCH_COMPLETE, payload: []})) ); }) );

this.action$是Effect类构造函数参数,被Angular DI框架注入:

effects.js.createEffectInstances:

action$.pipe里传入的三个操作:

(1) ofType - 通过filter operator实现

(2) debounceTime
(3) mergeMap

这三个operations的运行时结构:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

转载地址:https://jerry.blog.csdn.net/article/details/109048100 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SAP Spartacus RouteGuard路由守卫之CmsPageGuard
下一篇:SAP Spartacus Spinner控件显示原理

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年05月01日 02时27分53秒