I feel like many times packages in meteor doesn’t seem to work for me.
Since I’m still new to Meteor I wonder if misunderstood something somewhere.
My understanding is:
- You add a package to your project (meteor add author:package)
- You fire up meteor (meteor)
- You use the package as described
As an example:
I just did this for the matteodem:keybindings package.
Quickly tried to setup kaybindings like advised in on the github page:
Meteor.Keybindings.add({
'alt+a' : function () { console.log('alt+a'); },
'alt+b' : function () { console.log('alt+b'); },
'alt+c' : function () { console.log('alt+c'); }
});
Tried this both on the client and on the server.
My project crashes.
Am I missing something?
Hey man. I gave it a go, this package seems to crash your server when you place that code server side (specifically in Meteor.startup()
). Crash log reads
TypeError: Cannot call method 'add' of undefined *** at app/keybinding.js:31:24
I then placed it client-side (one again in Meteor.startup()
) and everything worked fine. I hope that helps. Are you getting a different error?
Hey markclayton,
thanks fot the help.
Now at least the app doesn’t crash anymore. Thats a step forward.
I placed the whole thing like this:
if (Meteor.isClient) {
Meteor.startup(function () {
Meteor.Keybindings.add({
'alt+a' : function () { console.log('alt+a'); },
'alt+b' : function () { console.log('alt+b'); },
'alt+c' : function () { console.log('alt+c'); }
});
});
}
I didn’t know that you could place the Meteor.startup on the client side as well.
Makes sense though.
In the console I still get a Uncaught TypeError: Cannot read property 'add' of undefined
Might this be happening because of my folder-structure?
I’ve already set up my “client” and “server” folders, but am not using them yet.
I’m still working in my root, in a big app.js file.
Ah yeah. First thing it’s always good to structure your app accordingly, at least using /server /lib and /client. See Reference http://docs.meteor.com/#/full/structuringyourapp . I’m not sure why you are still seeing that bug, as long as it’s running client-side you should be good. Hmm whats the stack trace say?