Created
August 10, 2013 23:27
-
-
Save drew-gross/6202629 to your computer and use it in GitHub Desktop.
Buggy Meteor App
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
/* CSS declarations go here */ |
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
<head> | |
<title>DrinkTabThing</title> | |
</head> | |
<body> | |
{{renderPage}} | |
</body> | |
<template name="tab"> | |
<h1>Menu</h1> | |
{{#each drinks_menu}} | |
{{> drink_from_menu}} | |
{{/each}} | |
<hr> | |
<h1>My Tab</h1> | |
{{#each ordered_drinks}} | |
{{> drink_from_tab}} | |
{{/each}} | |
</template> | |
<template name="drink_from_menu"> | |
<div>{{name}}: ${{price}}<input type="button" value="buy one" class="buy_drink"/></div> | |
</template> | |
<template name="drink_from_tab"> | |
<div>{{name}}: ${{price}}</div> | |
</template> |
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
Tabs = new Meteor.Collection('tabs'); | |
Drinks = new Meteor.Collection('drinks'); | |
if (Meteor.isClient) { | |
Meteor.Router.add({ | |
'/': 'home', | |
'/tabs/:id': function (id) { | |
Session.set('tabId', id); | |
return 'tab'; | |
} | |
}); | |
Template.tab.drinks_menu = function(){ | |
return Drinks.find({}); | |
}; | |
Template.tab.ordered_drinks = function () { | |
return Tabs.findOne(Session.get('tabId')).ordered_drinks; | |
}; | |
Template.drink_from_menu.events({ | |
'click .buy_drink': function () { | |
Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}}); | |
} | |
}); | |
} | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
Meteor.Router.add({ | |
'/tabs/:id.xml': function(id) { | |
return Tabs.findOne(id).owner; | |
} | |
}); | |
if (Drinks.find().count() === 0) { | |
Drinks.insert({name: "Screwdriver", price: "5.00"}); | |
Drinks.insert({name: "Rum and Coke", price: "5.50"}); | |
Drinks.insert({name: "Kilkenny's", price: "8.00"}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I put together a fixed version of this here: https://github.com/alanning/meteor-buggy-fix