如何在没有重新选择库的情况下从ngrx商店获取状态?

时间:2017-06-25 19:48:07

标签: ngrx ngrx-store

如何在不使用此store.select中的reselect createSelectorexample方法的情况下从 ngrx商店获取状态?

export const getBookCollection = createSelector(getBookEntities, getCollectionBookIds, (entities, ids) => { return ids.map(id => entities[id]); });

constructor(store: Store<fromRoot.State>) { this.books$ = store.select(fromRoot.getBookCollection); }

1 个答案:

答案 0 :(得分:1)

只使用store.select:

export const getBooksCollection = (state: State) => {
    const ids = state.collection.ids;
    const entities = state.books.entities;
    return ids.map(id => entities[id]);
}

constructor(store: Store<fromRoot.State>) {
    this.books$ = store.select(fromRoot.getBookCollection);
}