浏览代码

Use Meteor.setInterval() to update a session variable with a reactive display.

Frederic G. MARAND 8 年之前
父节点
当前提交
0f5d189667
共有 1 个文件被更改,包括 10 次插入6 次删除
  1. 10 6
      textcircle.js

+ 10 - 6
textcircle.js

@@ -2,6 +2,16 @@
 this.Documents = new Mongo.Collection("documents");
 
 if (Meteor.isClient) {
+  Meteor.setInterval(function () {
+    Session.set("current_date", new Date());
+  }, 1000);
+
+  Template.date_display.helpers({
+    current_date: function () {
+      return Session.get("current_date");
+    }
+  });
+
   Template.editor.helpers({
     docid: function () {
       let doc = Documents.findOne();
@@ -9,12 +19,6 @@ if (Meteor.isClient) {
     }
   });
 
-  Template.date_display.helpers({
-    current_date: function () {
-      return new Date();
-    }
-
-  });
 }
 
 if (Meteor.isServer) {