过滤状态在哪里?
发布时间:2020-12-17 07:14:36 所属栏目:安全 来源:网络整理
导读:新手问题:我有一个使用ngrx的angular2应用程序,我有一个服务,它将状态(可观察数组)返回给一个组件. 我的问题是,如果我想在组件中使用它的只读子集,我在哪里过滤状态? 我是在减速机,服务还是组件中进行的? 解决方法 可以在 ngrx example application中找到
新手问题:我有一个使用ngrx的angular2应用程序,我有一个服务,它将状态(可观察数组)返回给一个组件.
我的问题是,如果我想在组件中使用它的只读子集,我在哪里过滤状态? 我是在减速机,服务还是组件中进行的? 解决方法
可以在
ngrx example application中找到一些指导.有一种模式,其中选择器被定义为
alongside reducers:
/** * Because the data structure is defined within the reducer it is optimal to * locate our selector functions at this level. If store is to be thought of * as a database,and reducers the tables,selectors can be considered the * queries into said database. Remember to keep your selectors small and * focused so they can be combined and composed to fit each particular * use-case. */ export function getBookEntities() { return (state$: Observable<BooksState>) => state$ .select(s => s.entities); }; 那些选择器是used in (smart) components来选择/过滤状态: ... export class CollectionPage { books$: Observable<BooksInput>; constructor(store: Store<AppState>) { this.books$= store.let(getBookCollection()); } } 此模式/机制可用于过滤组件或服务中的状态 – 最适合您的体系结构. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |