Browse Source

Commit 11-5-3: using reactive-var.

Frederic G. MARAND 9 years ago
parent
commit
d7d8fc65cd
2 changed files with 6 additions and 11 deletions
  1. 1 0
      .meteor/packages
  2. 5 11
      facebook.js

+ 1 - 0
.meteor/packages

@@ -13,3 +13,4 @@ accounts-password
 ian:accounts-ui-bootstrap-3
 audit-argument-checks
 
+reactive-var

+ 5 - 11
facebook.js

@@ -1,22 +1,15 @@
 // Fonction hypothétique...
 function getFacebookLikeCount() {}
 
-var _currentLikeCount = 0;
-var _currentLikeCountListeners = new Tracker.Dependency();
-
-currentLikeCount = function () {
-  _currentLikeCountListeners.depend();
-  return _currentLikeCount;
-};
+var currentLikeCount = new ReactiveVar();
 
 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();
+      if (!err) {
+        currentLikeCount.set(count);
       }
     });
   }
@@ -25,7 +18,8 @@ Meteor.setInterval(function () {
 // Insert in "post_item.js".
 Template.postItem.helpers({
   likeCount: function () {
-    return currentLikeCount;
+    return currentLikeCount.get();
   }
 });
 
+// Note : similar feature for dictionaries in package "reactive-dict".