Przeglądaj źródła

Commit 11-5-1: polling example.

Frederic G. MARAND 8 lat temu
rodzic
commit
6eb8cbf47e
2 zmienionych plików z 25 dodań i 0 usunięć
  1. 1 0
      .jshintrc
  2. 24 0
      facebook.js

+ 1 - 0
.jshintrc

@@ -140,6 +140,7 @@
 
       // - Helpers
       "createCommentNotification": true,
+      "currentLikeCount": true,
       "ownsDocument": true,
       "throwError": true,
       "validatePost": true,

+ 24 - 0
facebook.js

@@ -0,0 +1,24 @@
+// Fonction hypothétique...
+function getFacebookLikeCount() {}
+
+currentLikeCount = 0;
+
+Meteor.setInterval(function () {
+  var postId;
+
+  if (Meteor.user() && postId === Session.get('currentPostId')) {
+    getFacebookLikeCount(Meteor.user(), Posts.find(postId).url, function (err, count) {
+      if (!err) {
+        currentLikeCount = count;
+      }
+    });
+  }
+}, 5 * 1000);
+
+// Insert in "post_item.js".
+Template.postItem.helpers({
+  likeCount: function () {
+    return currentLikeCount;
+  }
+});
+