Add "cell for view model" API to binding section controller
We should have a public API to get a cell given a view model in the binding section controller.
Question, how do we make this an O(1) operation? Right now we store an array of view models, but we'd have to do indexOfObject: to get the index, which is O(n).
What about potentially creating a lookup dictionary which maps the view models (or in particular, their diff identifiers) to indexes in the array? We would then need to make sure the lookup dictionary is updated whenever the property is set, potentially by implementing a custom setter. This would allow a O(1) lookup of the index.
The downside is that this moves the O(n) work to the time the view models update, which could potentially happen way more often than someone actually trying to retrieve a cell using this API.
@DimaVartanian 🤔 hmm ya that's a good point...
One possible optimization I can see is to update the dictionary lazily when this API is used. The dictionary could be constructed upon first trying to fetch a cell for a specific view model, and cleared when the view models array is changed. This would keep performance for existing functionality the same, while adding this new API with a O(n) runtime upon first access, and O(1) upon repeated access for the same array of view models. I could mock this up in a PR if you think it might be worthwhile. It seems like a reasonable compromise that accounts for the general case and keeps the API simple.
any update?