Created
October 20, 2012 22:12
-
-
Save lwille/3925008 to your computer and use it in GitHub Desktop.
pretty clean way of obtaining reactive item counts in meteor
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
Meteor.autosubscribe -> | |
Meteor.call 'getItemCount', Session.get('currentCustomer'), (err, count)-> | |
Session.set 'itemCount', count |
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
Template.foo.itemCount = -> | |
Session.get 'itemCount' |
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
Meteor.methods | |
getItemCount: (customer)-> | |
return Items.find(customer: customer).count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Side Note: Meteor.autosubscribe has been depreciated and replaced by Deps.autorun()
http://docs.meteor.com/#deps_autorun