I created an app which uses the flux pattern and pulls data from an API. This is updating data how it works now:
- Component calls the
get()
action - The action pulls data from an API
- The action dispatches a storechange event to the related store containing the new data
- The store updates its state with the received payload from the action and emits a viewchange event
- The component listens to the viewchange event, pulls the new items from the store and re-renders
This is working fine so far. But now I wonder how I would do filtering. E.g. for a specific component ("Notifications") I only want to return the unread notifications, or the notifications in a given time-period.
When I implement an action getByStatus(status)
getByDate(start, end)
, the whole store would only contain unread notifications or the ones in the time period, which is a problem when you want to show all notifications and the unread ones at the same time.
Is the only way to do this to create a filter-method with javascript / lodash or similiar? This would make any filtering on the server side obsolete and cause a lot of (uneeded) traffic.
And creating separate stores like "UnreadNotificationStore" would be pretty annyoing to handle, and in case of the time period the problem would still exist.
The only way I can think of is to add the getByStatus(status)
action without updating the store, and returning the data directly to the component.