in reading Mobx's documentation for its recommended best practices for defining data stores (see https://mobx.js.org/defining-data-stores.html), I see that the domain objects are stored in an array (in the example code "Example domain store, the TODOStore class contains a field "todos" which is an array). In that same class, functions like updateTodoFromServer and removeTodo do a linear scan matching by id by calling .find() or indexOf(). (The removeTodo function also has to call splice too!)
Normally, in a not-mobx context, based on this usage I would say that the todos field should actually be a map that allows you to look it up or delete it by "id" in constant time (or at least logarithmic time) rather than linear time.
BTW, in my own code, the number of items in the mobx store could theoretically be very large (if all possible items were pulled in)
- Is there a reason the mobx documentation examples use an array here?
- What if I used a map/ObservableMap instead? Is that better? Neutral? Not recommended?
- If maps are indeed better... does a normal map or an ObservableMap make more sense here?
Thanks in advance for helping me understand mobx better.
I tried reading mobx documentation and asking the question in a search engine and reading multiple search results, but I didn't find an explanation to my question yet.