Created
April 11, 2012 17:21
-
-
Save ryanflorence/2360685 to your computer and use it in GitHub Desktop.
Meteor.js Leader board example and some initial thoughts
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
// Set up a collection to contain player information. On the server, | |
// it is backed by a MongoDB collection named "players." | |
Players = new Meteor.Collection("players"); | |
if (Meteor.is_client) { | |
Template.leaderboard.players = function () { | |
return Players.find({}, {sort: {score: -1, name: 1}}); | |
}; | |
Template.leaderboard.selected_name = function () { | |
var player = Players.findOne(Session.get("selected_player")); | |
return player && player.name; | |
}; | |
Template.player.selected = function () { | |
return Session.equals("selected_player", this._id) ? "selected" : ''; | |
}; | |
Template.leaderboard.events = { | |
'click input.inc': function () { | |
Players.update(Session.get("selected_player"), {$inc: {score: 5}}); | |
} | |
}; | |
Template.player.events = { | |
'click': function () { | |
Session.set("selected_player", this._id); | |
} | |
}; | |
} | |
// On server startup, create some players if the database is empty. | |
if (Meteor.is_server) { | |
Meteor.startup(function () { | |
if (Players.find().count() === 0) { | |
var names = ["Ada Lovelace", | |
"Grace Hopper", | |
"Marie Curie", | |
"Carl Friedrich Gauss", | |
"Nikola Tesla", | |
"Claude Shannon"]; | |
for (var i = 0; i < names.length; i++) | |
Players.insert({name: names[i], score: Math.floor(Math.random()*10)*5}); | |
} | |
}); | |
} |
- No idea...
- No idea...
- No Idea... But this isn't rails or django. You have to think differently.
- I don't think so, It really depends how they had their MongoDB setup. It was localhost, so I suspect they were running mongo locally. When they switched to Depoly, they no longer used the chrome console (if I recall correctly).
- Rails and Django have no concept of this either. I'm not talking about page loads, I'm talking about pulling down a new JavaScript app dynamically without a page load.
A new JS App? Can you elaborate? I haven't seen that yet. I've basically tried every framework available for Node at this point.
snake_case
is the preferred convention in every other modern, dynamic language that I know of. Unfortunately JavaScript decided on using the less-readablecamelCase
. Most of the meteor API looks like it uses camelCase, with the exception of a few items likeis_client
andis_server
.- I'm not sure how meteor handles loading order.
- They don't support this yet.
- Meteor is still a prototype and proof of concept. The documentation mentions that they haven't built authentication engines into meteor yet. When that happens there will be proper permissions in place for DB actions. Until then, yes, the client has full database access.
@MichaelMartinez good example is a chat app in a sidebar or something. No sense downloading/initializing 500kb of JavaScript until the user actually wants to chat, then you fetch the chat app's assets and away you go.
@rpflorence They haven't secured the mongodb store yet. 0.3.x Give it some time. The base looks really good, however.
meteor apps are insecure by default during production. now you can type $"meteor remove insecure" prior to deployment to remove this rapid application development feature.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think meteorjs looks like a ton of fun, here are my initial questions:
What's with the
lame_underscore_naming
when every respectable JS API usescamelCase
Is there no commonjs module system? Docs indicate:
So my module dependency tree has to be in alphabetical order to avoid issues or what?
What if I want to defer loading large portions of the app? (its not uncommon for large apps to have "mini" apps that get loaded dynamically when they're needed).
Do people really have my DB at their fingertips in the browser console?