uma
uma

Reputation: 1577

How to convert follwoing selector of ngRx to boolean return?

Currently, I use the below filter to return some data list within the given date range. Actually, in the component, I checked only list length and according to that, assing True and False for the variable. I need to know how to convert this directly return boolean and is that way is correct?

export const selectModel = (planedDate: Date) => createSelector(
 selectDrugReviews,
 (reviews: ReviewModel[]) => reviews.filter(date => date.startDateTime.getTime() <= planedDate.getTime() && (date.endDateTime !== undefined ? date.endDateTime.getTime() >= planedDate.getTime() : true))
);

Upvotes: 0

Views: 1181

Answers (2)

Kamran Khatti
Kamran Khatti

Reputation: 4127

Try this

export const selectModel = (planedDate: Date) => createSelector(
 selectDrugReviews,
 (reviews: ReviewModel[]) => reviews.map((date) => date.startDateTime.getTime() <= planedDate.getTime() && (date.endDateTime !== undefined ? date.endDateTime.getTime() >= planedDate.getTime() : true))
);

Upvotes: 1

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30625

you need to use pipe map rather then filter.

map((date) => <condition here>));

Upvotes: 1

Related Questions