Pārlūkot izejas kodu

W3.4: store the id of the current document in the session.

Frederic G. MARAND 9 gadi atpakaļ
vecāks
revīzija
cf0373e8c7
1 mainītis faili ar 13 papildinājumiem un 2 dzēšanām
  1. 13 2
      textcircle.js

+ 13 - 2
textcircle.js

@@ -8,8 +8,8 @@ if (Meteor.isClient) {
   Template.editor.helpers({
     // Return the id of the first document you can find.
     docid: function () {
-      const doc = Documents.findOne();
-      return doc ? doc._id : undefined;
+      setupCurrentDocument();
+      return Session.get("docid");
     },
     // Configure the CodeMirror editor.
     config: function () {
@@ -121,6 +121,17 @@ Meteor.methods({
   }
 });
 
+function setupCurrentDocument() {
+  let doc;
+  // No docid set yet.
+  if (!Session.get("docid")) {
+    doc = Documents.findOne();
+    if (doc) {
+      Session.set("docid", doc._id);
+    }
+  }
+}
+
 // This renames object keys by removing hyphens to make them compatible
 // with spacebars.
 function fixObjectsKeys(obj) {