Created
March 8, 2013 03:11
-
-
Save anonymous/5113947 to your computer and use it in GitHub Desktop.
Simple meteor pub/sub example.
This file contains hidden or 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
| ["posts ready..."] | |
| > Meteor.call('addPost', {header: 'testheader', content: 'testcontent'}, function(err, res) {console.debug(err, res)}); | |
| undefined | |
| undefined Object {_str: "9f1cf3e2909abf6a69630e6e"} | |
| //now i expect a ["posts ready..."]? |
This file contains hidden or 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
| if(Meteor.isClient) { | |
| var Posts = new Meteor.Collection('posts', { | |
| idGeneration: 'MONGO' | |
| }); | |
| Meteor.autorun(function() { | |
| Meteor.subscribe('posts', function() { | |
| console.debug('posts ready...'); | |
| }); | |
| }); | |
| } |
This file contains hidden or 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
| preserve-inputs | |
| accounts-base | |
| accounts-password | |
| bootstrap | |
| ejson | |
| handlebars | |
| jquery | |
| less | |
| showdown | |
| underscore |
This file contains hidden or 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
| $>NODE_OPTIONS="--debug=5858" MONGO_URL="mongodb://127.0.0.1/database" meteor --settings server/settings.json | |
| [[[[[ ~/example ]]]]] | |
| Running on: http://localhost:3000/ | |
| debugger listening on port 5858 |
This file contains hidden or 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
| if(Meteor.isServer) { | |
| var Posts = new Meteor.Collection('posts', { | |
| idGeneration: 'MONGO' | |
| }); | |
| Meteor.publish('posts', function() { | |
| return Posts.find(); | |
| }); | |
| Meteor.methods({ | |
| 'addPost': function(data) { | |
| return Posts.insert({ | |
| header: data.header, | |
| content: data.content | |
| }, function(err) { | |
| if(err) { | |
| throw new Meteor.Error(500, 'internal server error!'); | |
| } | |
| }); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment