12345678910111213141516171819202122232425262728293031 |
- // Fonction hypothétique...
- function getFacebookLikeCount() {}
- var _currentLikeCount = 0;
- var _currentLikeCountListeners = new Tracker.Dependency();
- currentLikeCount = function () {
- _currentLikeCountListeners.depend();
- return _currentLikeCount;
- };
- Meteor.setInterval(function () {
- var postId;
- if (Meteor.user() && postId === Session.get('currentPostId')) {
- getFacebookLikeCount(Meteor.user(), Posts.find(postId).url, function (err, count) {
- if (!err && count !== _currentLikeCount) {
- currentLikeCount = count;
- _currentLikeCountListeners.changed();
- }
- });
- }
- }, 5 * 1000);
- // Insert in "post_item.js".
- Template.postItem.helpers({
- likeCount: function () {
- return currentLikeCount;
- }
- });
|