javascript - Canonical Way to use JQueryUI Autocomplete with Meteor -



javascript - Canonical Way to use JQueryUI Autocomplete with Meteor -

using meteor, i'd understand efficient way utilize jquery ui's autocomplete big volumes of server-side data.

i have 2 working proposals , hear opinions on differences , if there improve ways same thing.

using pub/sub:

class="lang-js prettyprint-override">// server meteor.publish("autocompletedata", function (thesearchterm) { var query = { name: { $regex: thesearchterm, $options: 'i'} }; homecoming mydata.find(query, options); }); // client template.mytemplate.rendered = function() { initautocomplete($(this.find('.my.autocomplete'))); }; var initautocomplete = function(element){ element.customautocomplete({ source: function(request, callback){ var sub = meteor.subscribe('autocompletedata', request.term, function(){ var results = mydata.find({}, {limit: 50}).fetch(); sub.stop(); callback(results); }); }, select: function(event, ui){ // stuff selected value } }); };

using remote functions (meteor.methods):

class="lang-js prettyprint-override">// server meteor.methods({ getdata: function(thesearchterm) { var query = { name: { $regex: thesearchterm, $options: 'i'} }; homecoming mydata.find(query, {limit: 50}).fetch(); }); }); // client template.mytemplate.rendered = function() { initautocomplete($(this.find('.my.autocomplete'))); }; var initautocomplete = function(element){ element.customautocomplete({ source: function(request, callback){ meteor.call('getdata', request.term, function(err, results){ callback(results); }); }, select: function(event, ui){ // stuff selected value } }); };

which, if either, the efficient way setup server-side autocomplete using meteor big dataset?

for it's worth, i'll offer few of thoughts on subject. disclaimer, i'm meteor enthusiast , not expert, please right me if i've said faulty.

to me, seems potential advantage of pub/sub in cases these info cached. when subscribing same record set, lookup near instantaneous since client can search local cache instead of asking server info 1 time again (publication smart plenty not force repeated info client).

however, advantage lost here since you're stopping subscription, every time user types same search term, info 1 time again pushed client (at least, cursor's added event fires 1 time again every document). in case expect pub/sub on equal footing meteor.call.

if want cache info of pub/sub, 1 way take out sub.stop(). unless users have tendency search similar terms, caching info worse since every letter user types more info stored on client, perhaps never seen 1 time again (unless searching such prominent feature in app user benefit this?).

overall, see no compelling advantage using pub/sub on meteor methods, though i'm not versed in meteor plenty offer more specific advantages/disadvantages between two. think meteor methods looks cleaner though.

if you're trying implement search feature though, easy-search package, supports type of server-side search autocomplete. in case, hope question resolved! i'm curious know reply too.

javascript meteor jquery-ui-autocomplete

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -