Skip to content

Instantly share code, notes, and snippets.

@andrewlorenz
Created November 15, 2016 16:59
Show Gist options
  • Save andrewlorenz/16be3d318ec6c3937677a1fb637ce1f3 to your computer and use it in GitHub Desktop.
Save andrewlorenz/16be3d318ec6c3937677a1fb637ce1f3 to your computer and use it in GitHub Desktop.
meteor data subscriptions using promise to ensure all data has been delivered to the client
Meteor data subscription
how to ensure all data has been delivered to the client before continuing
(e.g. in order to initialise a jQuery object that must have all UI elements present)
//-------------------------------------------------------------------
Template.sample.onCreated(function() {
//-------------------------------------------------------------------
allDataReady = new Promise(function(resolve){
self.subscribe([subscription_name],[subscription_parms],() => {
Tracker.afterFlush(function () { resolve(); });
});
});
});
//-------------------------------------------------------------------
Template.sample.onRendered(function() {
//-------------------------------------------------------------------
allDataReady.then(() => {
$("#elementId").sortable({
axis:"y",
helper:"clone",
placeholder: "shoplist-item-placeholder",
start: function(event,ui) {
ui.placeholder.height(ui.item.height());
}
}).disableSelection().sortable("disable");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment