如何在不重新选择库的情况下从 ngrx 商店获取状态?
How to get the state from the ngrx store without reselect library?
如何在不使用 reselect createSelector
和 store.select method in this example 的情况下从 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);
}
仅使用 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);
}
如何在不使用 reselect createSelector
和 store.select method in this example 的情况下从 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);
}
仅使用 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);
}