I’ve got a route planner app where a Ride hasMany Waypoints. I’m talking to a rails back end with JSONAPI. I want to offer the ability to insert a new waypoint between existing ones and also to remove waypoints and have the surrounding two re-order appropriately. I was thinking of either:
Having some sort of re-ordering callback on the rails model that, when a new Waypoint record is persisted with a specified
positionattribute, it forces a recalculation of the
positionattribute for all subsequent Waypoints already part of the Ride.
Manage this as part of the model creation function on Ember and update multiple local models, causing N subsequent update requests where N=number of waypoints after the newly inserted. Same for deletions.
This is purely subjective but the first option feels like the right thing to do because it feels more robust but it introduces the problem of having to get the changes back reflected in the Ember store. The latter feels bit fragile and potentially heavy on server traffic given how JSONAPI triggers one query per model updated.
I also don’t really know how well ember-data manages what would need to be websocket/push requests.
I’d be interested to hear if anyone has an opinion on the above and if there is a better way I may not have considered?