wonderful world
wonderful world

Reputation: 11599

How to get the state from the ngrx store without reselect library?

How to get the state from the ngrx store without using the reselect createSelector and store.select method in this example?

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); }

Upvotes: 0

Views: 92

Answers (1)

seescode
seescode

Reputation: 2131

Using only the store.select you could do:

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);
}

Upvotes: 1

Related Questions