Correct pattern for loading data for edit form?


#1

I’m implementing a proof of concept using Meteor and slowly picking up the framework as I go. I’m about to implement a form for editing an item in a collection, and I’m wondering what the correct practice is for loading the data?

If I understand subscriptions correctly, if I create a subscription to load a document by a specific ID in the edit form template, and then bind those values to the form on the client, then any other users of the app that update the same document will cause the subscription to fire and update the values bound to the form - is that correct?

If so, then obviously that’s not what I want. My assumption is that the best thing to do here would be to use a Method call to load the data in a more “RPC-like” style, and then implement my own optimistic locking mechanism to detect concurrent updates?

Hopefully I’ve explained that well enough! Just looking for guidance on what the correct “Meteor way” to do this.

Thanks


#2

You might want to have a look at this: https://docs.meteor.com/api/collections.html#Mongo-Cursor-observe

You could do exactly what you described:

if I create a subscription to load a document by a specific ID in the edit form template, and then bind those values to the form on the client, then any other users of the app that update the same document will cause the subscription to fire and update the values bound to the form

But you would listen for changes coming from other users, and you can decide on an per-“item” case if you would want to update the document or not (if not, you would need to decouple the current item from the collection, since you can’t force it to not update)

I hope this is what you were looking for.