1

Consider a typical list app, written in Meteor. When a user adds a new item to the list, Meteor will run its method on the client and the server to enable the ui to update very quickly. Is there a way of telling whether an item in the list is simulated, client-side data or data that has been successfully stored server-side?

My use case in this example would be to apply a different styling to new list items until they had been ran server-side. What's the best way of achieving a different appearance depending on the status of the data in question?

Many thanks.

1 Answer 1

2

you can use collection-hooks before.insert (https://github.com/matb33/meteor-collection-hooks) in order to add a insertedAt date for example (or a flag) so that on client side, as long as you do not have your 'flag' it means it's in a pending insert status, so that you can apply a different display on your object.

Hope this help. regs.

2
  • 1
    This is a good pattern. Setting the insertedAt or createdAt date on the server means your time is always synchronized and not gameable by the client. The simple absence of this key on the client tells you the data is still simulated. Nov 10, 2016 at 18:35
  • That is perfect, very clean way of accomplishing what I'm after. Thank you both. Nov 21, 2016 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.