Created
May 28, 2015 20:27
-
-
Save robomatic/35d9520333dfabf75dbc to your computer and use it in GitHub Desktop.
meteor method call error
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
Comments = new Mongo.Collection('comments'); | |
if (Meteor.isClient) { | |
Meteor.subscribe('allComments'); | |
Meteor.call("callMe", "Rob", function(err, result) { | |
if (err) throw err; | |
console.log('result: ' + result); | |
}); | |
Template.CommentList.helpers({ | |
comments: function () { | |
return Comments.find(); | |
}, | |
formatTimestamp: function (timestamp) { | |
return moment(timestamp).fromNow(); | |
} | |
}); | |
Template.CommentAdd.events({ | |
'submit form': function (e, tmpl) { | |
e.preventDefault(); | |
var form = tmpl.find('form'); | |
var commentEl = tmpl.find('[name=comment]'); | |
var comment = commentEl.value; | |
Comments.insert({ | |
login: 'cmather', | |
timestamp: new Date, | |
room: 'test', | |
comment: 'test comment' | |
}) | |
} | |
}) | |
} | |
if (Meteor.isServer) { | |
Meteor.methods({ | |
callMe: function (name) { | |
return "hello, " + name; | |
} | |
}); | |
Meteor.publish('allComments', function(){ | |
var cursor = Comments.find(); | |
var self = this; | |
var observeHandle = cursor.observeChanges({ | |
added: function(id, fields) { | |
self.added('comments', id, fields) | |
}, | |
changed: function (id, fields) { | |
self.changed('comments', id, fields) | |
}, | |
removed: function (id) { | |
self.removed('comments', id) | |
} | |
}); | |
this.ready(); | |
this.onStop(function (){ | |
observeHandle.stop(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment