Last active
August 29, 2015 14:22
-
-
Save jackiig/b3365d093049cc69a6eb to your computer and use it in GitHub Desktop.
Tracker / ReactiveVar in Flack
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
Template.CommentAdd.events({ | |
'submit form': function(e, tmpl) { | |
e.preventDefault(); | |
formEl = tmpl.find('form'); | |
comment = tmpl.find('[name=comment]').value; | |
if (comment.trim().length == 0) { return false; }; | |
Comments.insert({ | |
login: Meteor.user().profile.login, | |
timestamp: new Date, | |
room: Session.get('activeRoom'), | |
comment: comment | |
}, function(err, res) { | |
if (err) { throw err }; | |
console.log('Inserted comment', res); | |
}); | |
formEl.reset(); | |
chatCount.set($('.comment-item').length); | |
} | |
}); | |
chatCount = new ReactiveVar; | |
Tracker.autorun(function() { | |
Session.get('activeRoom'); | |
chatCount.get(); | |
var newHeight = $('.comment-list').height(); | |
$('.main-list').animate({scrollTop: newHeight}, 'slow'); | |
}); | |
Template.CommentItem.onRendered(function() { | |
chatCount.set($('.comment-item').length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment