facebook.js 744 B

12345678910111213141516171819202122232425262728293031
  1. // Fonction hypothétique...
  2. function getFacebookLikeCount() {}
  3. var _currentLikeCount = 0;
  4. var _currentLikeCountListeners = new Tracker.Dependency();
  5. currentLikeCount = function () {
  6. _currentLikeCountListeners.depend();
  7. return _currentLikeCount;
  8. };
  9. Meteor.setInterval(function () {
  10. var postId;
  11. if (Meteor.user() && postId === Session.get('currentPostId')) {
  12. getFacebookLikeCount(Meteor.user(), Posts.find(postId).url, function (err, count) {
  13. if (!err && count !== _currentLikeCount) {
  14. currentLikeCount = count;
  15. _currentLikeCountListeners.changed();
  16. }
  17. });
  18. }
  19. }, 5 * 1000);
  20. // Insert in "post_item.js".
  21. Template.postItem.helpers({
  22. likeCount: function () {
  23. return currentLikeCount;
  24. }
  25. });