Преглед на файлове

Move ReactiveCache to imports

- so it's available for the Server too
Martin Filser преди 2 години
родител
ревизия
16130b3f73
променени са 3 файла, в които са добавени 46 реда и са изтрити 14 реда
  1. 0 14
      client/lib/reactiveCache.js
  2. 45 0
      imports/reactiveCache.js
  3. 1 0
      models/cards.js

+ 0 - 14
client/lib/reactiveCache.js

@@ -1,14 +0,0 @@
-import { DataCache } from 'meteor-reactive-cache';
-
-// global Reactive Cache class to avoid big overhead while searching for the same data often again
-ReactiveCache = {
-  getBoard(id) {
-    if (!this.__board) {
-      this.__board = new DataCache(boardId => {
-        return Boards.findOne(boardId);
-      });
-    }
-    const ret = this.__board.get(id);
-    return ret;
-  }
-}

+ 45 - 0
imports/reactiveCache.js

@@ -0,0 +1,45 @@
+import { DataCache } from 'meteor-reactive-cache';
+
+// Server isn't reactive, so search for the data always.
+ReactiveCacheServer = {
+  getBoard(id) {
+    const ret = Boards.findOne(id);
+    return ret;
+  },
+}
+
+// only the Client is reactive
+// saving the result has a big advantage if the query is big and often searched for the same data again and again
+// if the data is changed in the client, the data is saved to the server and depending code is reactive called again
+ReactiveCacheClient = {
+  getBoard(id) {
+    if (!this.__board) {
+      this.__board = new DataCache(boardId => {
+        const _ret = Boards.findOne(boardId);
+        return _ret;
+      });
+    }
+    const ret = this.__board.get(id);
+    return ret;
+  }
+}
+
+// global Reactive Cache class to avoid big overhead while searching for the same data often again
+// This class calls 2 implementation, for server and client code
+//
+// having this class here has several advantages:
+// - The Programmer hasn't to care about in which context he call's this class
+// - having all queries together in 1 class to make it possible to see which queries in Wekan happens, e.g. with console.log
+ReactiveCache = {
+  getBoard(id) {
+    let ret;
+    if (Meteor.isServer) {
+      ret = ReactiveCacheServer.getBoard(id);
+    } else {
+      ret = ReactiveCacheClient.getBoard(id);
+    }
+    return ret;
+  },
+}
+
+export { ReactiveCache };

+ 1 - 0
models/cards.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 import {
   ALLOWED_COLORS,