lundi 10 avril 2017

Reduz build index of object

In a redux app lets say its a blog. State can look like { Posts: { 1:{day:'2016-03-13', id:1}, 2:{day:'2016-03-14',id:2}, ..... } }

Now in a certain component i want to show all posts of a specific day, i can filte all posts using Array.filter to get posts of this day, but this mean that if i have 1000's of post every time component refresh it will recalculate whole filter.

So in such circumstances i think its better if i had an index in redux store something like

{ PostsByDate:{ '2017-03-13': [1,2], .. Etc } }

So how to build such index and make sure that its always in sync with posts object ?

Aucun commentaire:

Enregistrer un commentaire