DEV: Move `preload-store` to `discourse/lib/preload-store`

DEV: Move preload-store to discourse/lib/preload-store

It’s only used inside Discourse so it needn’t be its own module

diff --git a/app/assets/javascripts/admin/routes/admin-backups-logs.js b/app/assets/javascripts/admin/routes/admin-backups-logs.js
index 3d24756..2c7e16e 100644
--- a/app/assets/javascripts/admin/routes/admin-backups-logs.js
+++ b/app/assets/javascripts/admin/routes/admin-backups-logs.js
@@ -1,6 +1,6 @@
 import EmberObject from "@ember/object";
 import Route from "@ember/routing/route";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 
 export default Route.extend({
   // since the logs are pushed via the message bus
diff --git a/app/assets/javascripts/admin/routes/admin-backups.js b/app/assets/javascripts/admin/routes/admin-backups.js
index 6bc42d7..85bfc19 100644
--- a/app/assets/javascripts/admin/routes/admin-backups.js
+++ b/app/assets/javascripts/admin/routes/admin-backups.js
@@ -4,7 +4,7 @@ import { ajax } from "discourse/lib/ajax";
 import showModal from "discourse/lib/show-modal";
 import BackupStatus from "admin/models/backup-status";
 import Backup from "admin/models/backup";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 import User from "discourse/models/user";
 
 const LOG_CHANNEL = "/admin/backups/logs";
diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js
index 5d189a2..e14a457 100644
--- a/app/assets/javascripts/discourse-loader.js
+++ b/app/assets/javascripts/discourse-loader.js
@@ -6,7 +6,8 @@ var define, requirejs;
   var ALIASES = {
     "ember-addons/ember-computed-decorators":
       "discourse-common/utils/decorators",
-    "discourse/lib/raw-templates": "discourse-common/lib/raw-templates"
+    "discourse/lib/raw-templates": "discourse-common/lib/raw-templates",
+    "preload-store": "discourse/lib/preload-store"
   };
   if (typeof Ember !== "undefined") {
     EMBER_MODULES = {
diff --git a/app/assets/javascripts/discourse/app/adapters/topic-list.js b/app/assets/javascripts/discourse/app/adapters/topic-list.js
index 3d28004..bd45b85 100644
--- a/app/assets/javascripts/discourse/app/adapters/topic-list.js
+++ b/app/assets/javascripts/discourse/app/adapters/topic-list.js
@@ -1,6 +1,6 @@
 import { ajax } from "discourse/lib/ajax";
 import RestAdapter from "discourse/adapters/rest";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 
 export function finderFor(filter, params) {
   return function() {
diff --git a/app/assets/javascripts/discourse/app/helpers/custom-html.js b/app/assets/javascripts/discourse/app/helpers/custom-html.js
index b9d424a..202476f 100644
--- a/app/assets/javascripts/discourse/app/helpers/custom-html.js
+++ b/app/assets/javascripts/discourse/app/helpers/custom-html.js
@@ -1,4 +1,4 @@
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 import { htmlSafe } from "@ember/template";
 
 let _customizations = {};
diff --git a/app/assets/javascripts/discourse/app/initializers/banner.js b/app/assets/javascripts/discourse/app/initializers/banner.js
index ccec6a9..91e3ab3 100644
--- a/app/assets/javascripts/discourse/app/initializers/banner.js
+++ b/app/assets/javascripts/discourse/app/initializers/banner.js
@@ -1,5 +1,5 @@
 import EmberObject from "@ember/object";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 
 export default {
   name: "banner",
diff --git a/app/assets/javascripts/discourse/app/initializers/enable-emoji.js b/app/assets/javascripts/discourse/app/initializers/enable-emoji.js
index a6e3e6d..fd91b69 100644
--- a/app/assets/javascripts/discourse/app/initializers/enable-emoji.js
+++ b/app/assets/javascripts/discourse/app/initializers/enable-emoji.js
@@ -1,6 +1,6 @@
 import { withPluginApi } from "discourse/lib/plugin-api";
 import { registerEmoji } from "pretty-text/emoji";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 
 export default {
   name: "enable-emoji",
diff --git a/app/assets/javascripts/discourse/app/lib/preload-store.js b/app/assets/javascripts/discourse/app/lib/preload-store.js
new file mode 100644
index 0000000..ebee66c
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/lib/preload-store.js
@@ -0,0 +1,54 @@
+//  We can insert data into the PreloadStore when the document is loaded.
+// The data can be accessed once by a key, after which it is removed
+import { Promise } from "rsvp";
+
+export default {
+  data: {},
+
+  store(key, value) {
+    this.data[key] = value;
+  },
+
+  /**
+    To retrieve a key, you provide the key you want, plus a finder to load
+    it if the key cannot be found. Once the key is used once, it is removed
+    from the store.
+    So, for example, you can't load a preloaded topic more than once.
+  **/
+  getAndRemove(key, finder) {
+    if (this.data[key]) {
+      let promise = Promise.resolve(this.data[key]);
+      delete this.data[key];
+      return promise;
+    }
+
+    if (finder) {
+      return new Promise(function(resolve, reject) {
+        let result = finder();
+
+        // If the finder returns a promise, we support that too
+        if (result && result.then) {
+          result
+            .then(toResolve => resolve(toResolve))
+            .catch(toReject => reject(toReject));
+        } else {
+          resolve(result);
+        }
+      });
+    }
+
+    return Promise.resolve(null);
+  },
+
+  get(key) {
+    return this.data[key];
+  },
+
+  remove(key) {
+    if (this.data[key]) delete this.data[key];
+  },
+
+  reset() {
+    this.data = {};
+  }
+};
diff --git a/app/assets/javascripts/discourse/app/models/category-list.js b/app/assets/javascripts/discourse/app/models/category-list.js
index ce65597..e3c028e 100644
--- a/app/assets/javascripts/discourse/app/models/category-list.js
+++ b/app/assets/javascripts/discourse/app/models/category-list.js
@@ -1,5 +1,5 @@
 import ArrayProxy from "@ember/array/proxy";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 import { ajax } from "discourse/lib/ajax";
 import Topic from "discourse/models/topic";
 import Category from "discourse/models/category";
diff --git a/app/assets/javascripts/discourse/app/models/site.js b/app/assets/javascripts/discourse/app/models/site.js
index 29de94c..455368b 100644
--- a/app/assets/javascripts/discourse/app/models/site.js
+++ b/app/assets/javascripts/discourse/app/models/site.js
@@ -7,7 +7,7 @@ import PostActionType from "discourse/models/post-action-type";
 import Singleton from "discourse/mixins/singleton";
 import RestModel from "discourse/models/rest";
 import TrustLevel from "discourse/models/trust-level";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 import deprecated from "discourse-common/lib/deprecated";
 
 const Site = RestModel.extend({
diff --git a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js
index bccb774..7cb74d8 100644
--- a/app/assets/javascripts/discourse/app/models/topic-tracking-state.js
+++ b/app/assets/javascripts/discourse/app/models/topic-tracking-state.js
@@ -2,7 +2,7 @@ import EmberObject, { get } from "@ember/object";
 import { isEmpty } from "@ember/utils";
 import { NotificationLevels } from "discourse/lib/notification-levels";
 import discourseComputed, { on } from "discourse-common/utils/decorators";
-import PreloadStore from "preload-store";
+import PreloadStore from "discourse/lib/preload-store";
 import Category from "discourse/models/category";
 import User from "discourse/models/user";
 
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index 00f8c88..573104b 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js

[... diff too long, it was truncated ...]

GitHub sha: 01929e35