about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNolan Lawson <nolan@nolanlawson.com>2017-10-03 11:43:57 -0700
committerEugen Rochko <eugen@zeonfederated.com>2017-10-03 20:43:57 +0200
commit82d9ade7a6abc663b30b3df4ae08a8980d61e233 (patch)
treeb6c07546856b94c1da4010208726168c2e8be1cc
parent875d943c189afe9887200f357d916a9f8fd19fe8 (diff)
Compress emoji_data_light.js (#5201)
-rw-r--r--app/javascript/mastodon/emoji_data_compressed.js22
-rw-r--r--app/javascript/mastodon/emoji_data_light.js27
2 files changed, 35 insertions, 14 deletions
diff --git a/app/javascript/mastodon/emoji_data_compressed.js b/app/javascript/mastodon/emoji_data_compressed.js
new file mode 100644
index 000000000..f69a3e46a
--- /dev/null
+++ b/app/javascript/mastodon/emoji_data_compressed.js
@@ -0,0 +1,22 @@
+// @preval
+const data = require('emoji-mart/dist/data').default;
+const pick = require('lodash/pick');
+const values = require('lodash/values');
+
+const condensedEmojis = Object.keys(data.emojis).map(key => {
+  if (!data.emojis[key].short_names[0] === key) {
+    throw new Error('The condenser expects the first short_code to be the ' +
+      'key. It may need to be rewritten if the emoji change such that this ' +
+      'is no longer the case.');
+  }
+  return values(pick(data.emojis[key], ['short_names', 'unified', 'search']));
+});
+
+// JSON.parse/stringify is to emulate what @preval is doing and avoid any
+// inconsistent behavior in dev mode
+module.exports = JSON.parse(JSON.stringify({
+  emojis: condensedEmojis,
+  skins: data.skins,
+  categories: data.categories,
+  short_names: data.short_names,
+}));
diff --git a/app/javascript/mastodon/emoji_data_light.js b/app/javascript/mastodon/emoji_data_light.js
index f03442455..f91ee592e 100644
--- a/app/javascript/mastodon/emoji_data_light.js
+++ b/app/javascript/mastodon/emoji_data_light.js
@@ -1,17 +1,16 @@
-// @preval
-const data = require('emoji-mart/dist/data').default;
-const pick = require('lodash/pick');
+const data = require('./emoji_data_compressed');
 
-const condensedEmojis = {};
-Object.keys(data.emojis).forEach(key => {
-  condensedEmojis[key] = pick(data.emojis[key], ['short_names', 'unified', 'search']);
+// decompress
+const emojis = {};
+data.emojis.forEach(compressedEmoji => {
+  const [ short_names, unified, search ] = compressedEmoji;
+  emojis[short_names[0]] = {
+    short_names,
+    unified,
+    search,
+  };
 });
 
-// JSON.parse/stringify is to emulate what @preval is doing and avoid any
-// inconsistent behavior in dev mode
-module.exports = JSON.parse(JSON.stringify({
-  emojis: condensedEmojis,
-  skins: data.skins,
-  categories: data.categories,
-  short_names: data.short_names,
-}));
+data.emojis = emojis;
+
+module.exports = data;