Friday, 26 May 2017

Meteor: Pick the same random item from an array in a method and its simulation

Using the Random package or any other techniques, is there a way to pick the same item from an array on the Client and the Server (for optimistic UI purposes)?

Example:

Meteor.methods({
    myMethod(): {
        var item = Random.choice([1, 2, 3, 4]); // Should return 2 on both client and server
    },
});

I know that Meteor uses a specific seed for every method invocation to generate the same _id for a document from the Client and the Server. So there must be a way to accomplish this!



via Alex Nault

No comments:

Post a Comment