21 Nov 2013, 3:46pm
meteor:

leave a comment




  • Anzeige
  • Mongo fails when starting meteor

    If your are see­ing this one when start­ing meteor:
    Unexpected mongo exit code 100. Restarting.
    Can't start mongod
    MongoDB had an unspecified uncaught exception.

    Check if mon­goDB is run­ning already, oth­er­wise, if you can find a file called .meteor/local/db/mongod.lock means that mongo did not stop prop­erly last time. Just delet­ing this lock file should fix it. It’s a bit unfor­tu­nate that the error mes­sage doesn’t give any hint in this direction.

    29 Oct 2013, 4:19pm
    meteor:

    leave a comment




  • Anzeige
  • Serving Static Files with Meteor and Spiderable

    In short: To serve files which are not part of your project’s code (i.e. which are sup­posed to be served with­out being com­piled), put them in the public folder. This folder will be served from /.

    Some more back­ground and details:
    Tried to add a web-font to my project, thus, I put it in /client/webfonts/somefont.woff. But the font didn’t show up. I tested it with wget -O- http://localhost:3000/webfonts/somefont.woff … and *sur­prise* I got the HTML of the default page — not some binary gib­ber­ish that you would expect to find in a font file.

    All file types unknown to meteor get stripped out dur­ing com­pile time. Instead you need to put them in a sep­a­rate folder called public — in my case in /public/webfonts/somefont.woff. Rookie mis­take I guess. :)

    7 Oct 2013, 10:07am
    javascript:

    1 comment




  • Anzeige
  • Callback Method for Twitter’s Typeahead

    When you start using Twitter’s typea­head, e.g. because you switched from Boot­strap 2.3 to 3.0, you will notice that it is NOT a sim­ple drop-in replace­ment for Bootstrap’s orig­i­nal typea­head!
    Before, you gen­er­ated the sug­ges­tions shown to the user by imple­ment­ing a call­back method while cre­at­ing the typea­head like this:

    $(field).typeahead({
      source: function(query, process) { 
        ... return a list of suggestions (see doc for details) 
      }
    });

    Since ver­sion 3, Boot­strap does not pro­vide its own typea­head any more, instead it is using Twitter’s own imple­men­ta­tion which seems to be a good choice at least on the long run. But it does not pro­vide any mean for defin­ing a call­back method to pro­vide the sug­ges­tions — no clue why.
    Instead you can pro­vide a pre­de­fined array locally, a pre­de­fined array that will be loaded on start-up, or a remote ser­vice defined by a URL.
    You will find sev­eral good exam­ples of why you need a call­back method sometimes.

    • You want/have to use a Javascript library to access the service.
    • There is no data­base for the sug­ges­tions, they a gen­er­ated on the fly, e.g.if you want to sug­gest sen­tence com­ple­tion while the user types.
    • You are using Meteor’s col­lec­tions hold­ing your sug­ges­tions, thus, there is no URL you could point to.

    But tak­ing a look into the inter­nals revealed fol­low­ing solu­tion: com­pletely by-pass the inter­nal sug­ges­tion aggre­ga­tion of Twitter’s typea­head by replac­ing the getSuggestions(query, callback) method of the first dataset, which we defined by local: [];.

    (t = $("field")).typeahead({ local: [] });
    t.data("ttView").datasets[0].getSuggestions = function(query, callback) {
      var suggestions = ... gather your suggestions here ...
      var data = [];
      for (suggestion in suggestions) { data.push(this._transformDatum(suggestion)); }
      callback(data)
    }

    (Trans­lated from Cof­fee­script on-the-fly — con­sider as a draft than an out-of-the-box solution.)

    Happy hack­ing. :)

    p.s. for Meteor users: The call­back breaks each time the tem­plate gets re-rendered — despite that you use the pack­age preserve-inputs or <#constant> due to a bug. Some­how, con­stant areas and that par­tic­u­lar pack­age do not get along with each other. Solu­tion: removed the pack­age and use con­stant areas around typea­head input fields works. This should be fixed as soon as the new tem­plate engine gets rolled out.