beaucouplus/calendar

Revamp events data structure

Closed this issue · 0 comments

The events data structure has changed quite a bit since the beginning.

At first I created an object, but when I added the possibility to, count, add or delete events I found it quite difficult to work with.

Then I went to a simple array, as I knew it would work pretty easily. The trade-off is that filtering events by date on every date is not efficient at all and I think it slows the app quite a bit.

I read about maps and sets and might probably use one of them as they seem to be a good in-between between objects and arrays.

Maps seems to really do the trick as they have interesting built in methods.

The main point for me right now is that I create a new id for each event I create.
With a key-value pair I would have to iterate over values and sum them to get the relevant count.
In fact, relying on the events count to provide an id for an item is probably not relevant.

I should create a unique-id state app-wise and use it when I create an event. I then could use maps easily to store events.

Something like

a = Map.new (or whatever way it is created)
a.add("2020-04-12", Map.new)

a.get("2020-04-12").get(event)