Created
November 15, 2016 16:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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