-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatapp.js
33 lines (31 loc) · 1015 Bytes
/
chatapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Messages = new Meteor.Collection('messages');
if (Meteor.is_client) {
Template.list.messages = function(){
return Messages.find({});
};
Template.newMessageTemplate.events = {
'submit form.add-new-message' : function(event){
event.preventDefault();
var messageTextInputField = $('input.message-text');
var messageText = messageTextInputField.val();
console.log(messageText);
Messages.insert({message : messageText});
messageTextInputField.val('');
}
};
}
if (Meteor.is_server) {
Meteor.startup(function () {
// code to run on server at startup
if (Messages.find().count() === 0) {
var initial_messages = ["Ada Lovelace",
"Grace Hopper",
"Marie Curie",
"Carl Friedrich Gauss",
"Nikola Tesla",
"Claude Shannon"];
for (var i = 0; i < initial_messages.length; i++)
Messages.insert({message : initial_messages[i]});
}
});
}