From 178ff1672d60320a5fbb8c11133eaee4a14c3781 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 11 Jun 2020 18:44:45 +0200 Subject: PersistedState: Replace object-path with lodash function We were loading that one anyway. --- src/lib/persisted_state.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index cad7ea25..8ecb66a8 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -1,13 +1,12 @@ import merge from 'lodash.merge' -import objectPath from 'object-path' import localforage from 'localforage' -import { each } from 'lodash' +import { each, get, set } from 'lodash' let loaded = false const defaultReducer = (state, paths) => ( paths.length === 0 ? state : paths.reduce((substate, path) => { - objectPath.set(substate, path, objectPath.get(state, path)) + set(substate, path, get(state, path)) return substate }, {}) ) -- cgit v1.2.3-70-g09d2 From 9bfb3754c1bc0d1033afda97f2884e721d1ab3d8 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 13 Jun 2020 11:47:34 +0200 Subject: ServiceWorker: Use loader to only notification messages. This keeps the translation size very small and makes it easy to integrate all the languages, as dynamically loading them isn't easy in the service worker. --- src/lib/notification-i18n-loader.js | 9 ++++++ src/sw.js | 55 +++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 src/lib/notification-i18n-loader.js (limited to 'src/lib') diff --git a/src/lib/notification-i18n-loader.js b/src/lib/notification-i18n-loader.js new file mode 100644 index 00000000..a61755c8 --- /dev/null +++ b/src/lib/notification-i18n-loader.js @@ -0,0 +1,9 @@ +// This somewhat mysterious module +module.exports = function(source) { + var object = JSON.parse(source) + var smol = { + notifications: object.notifications || {} + } + + return JSON.stringify(smol) +} diff --git a/src/sw.js b/src/sw.js index d0050b24..6e31516a 100644 --- a/src/sw.js +++ b/src/sw.js @@ -1,4 +1,5 @@ /* eslint-env serviceworker */ +/* eslint-disable import/no-webpack-loader-syntax */ import localForage from 'localforage' import { parseNotification } from './services/entity_normalizer/entity_normalizer.service.js' @@ -7,33 +8,33 @@ import Vue from 'vue' import VueI18n from 'vue-i18n' const messages = { - ar: require('./i18n/ar.json'), - ca: require('./i18n/ca.json'), - cs: require('./i18n/cs.json'), - de: require('./i18n/de.json'), - eo: require('./i18n/eo.json'), - es: require('./i18n/es.json'), - et: require('./i18n/et.json'), - eu: require('./i18n/eu.json'), - fi: require('./i18n/fi.json'), - fr: require('./i18n/fr.json'), - ga: require('./i18n/ga.json'), - he: require('./i18n/he.json'), - hu: require('./i18n/hu.json'), - it: require('./i18n/it.json'), - ja: require('./i18n/ja_pedantic.json'), - ja_easy: require('./i18n/ja_easy.json'), - ko: require('./i18n/ko.json'), - nb: require('./i18n/nb.json'), - nl: require('./i18n/nl.json'), - oc: require('./i18n/oc.json'), - pl: require('./i18n/pl.json'), - pt: require('./i18n/pt.json'), - ro: require('./i18n/ro.json'), - ru: require('./i18n/ru.json'), - te: require('./i18n/te.json'), - zh: require('./i18n/zh.json'), - en: require('./i18n/en.json') + ar: require('./lib/notification-i18n-loader.js!./i18n/ar.json'), + ca: require('./lib/notification-i18n-loader.js!./i18n/ca.json'), + cs: require('./lib/notification-i18n-loader.js!./i18n/cs.json'), + de: require('./lib/notification-i18n-loader.js!./i18n/de.json'), + eo: require('./lib/notification-i18n-loader.js!./i18n/eo.json'), + es: require('./lib/notification-i18n-loader.js!./i18n/es.json'), + et: require('./lib/notification-i18n-loader.js!./i18n/et.json'), + eu: require('./lib/notification-i18n-loader.js!./i18n/eu.json'), + fi: require('./lib/notification-i18n-loader.js!./i18n/fi.json'), + fr: require('./lib/notification-i18n-loader.js!./i18n/fr.json'), + ga: require('./lib/notification-i18n-loader.js!./i18n/ga.json'), + he: require('./lib/notification-i18n-loader.js!./i18n/he.json'), + hu: require('./lib/notification-i18n-loader.js!./i18n/hu.json'), + it: require('./lib/notification-i18n-loader.js!./i18n/it.json'), + ja: require('./lib/notification-i18n-loader.js!./i18n/ja_pedantic.json'), + ja_easy: require('./lib/notification-i18n-loader.js!./i18n/ja_easy.json'), + ko: require('./lib/notification-i18n-loader.js!./i18n/ko.json'), + nb: require('./lib/notification-i18n-loader.js!./i18n/nb.json'), + nl: require('./lib/notification-i18n-loader.js!./i18n/nl.json'), + oc: require('./lib/notification-i18n-loader.js!./i18n/oc.json'), + pl: require('./lib/notification-i18n-loader.js!./i18n/pl.json'), + pt: require('./lib/notification-i18n-loader.js!./i18n/pt.json'), + ro: require('./lib/notification-i18n-loader.js!./i18n/ro.json'), + ru: require('./lib/notification-i18n-loader.js!./i18n/ru.json'), + te: require('./lib/notification-i18n-loader.js!./i18n/te.json'), + zh: require('./lib/notification-i18n-loader.js!./i18n/zh.json'), + en: require('./lib/notification-i18n-loader.js!./i18n/en.json') } Vue.use(VueI18n) -- cgit v1.2.3-70-g09d2 From 1e57adf6d4a46ab5be677bba7ae3c7f0ba0fc520 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 13 Jun 2020 11:53:16 +0200 Subject: Linting + docs --- src/lib/notification-i18n-loader.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/notification-i18n-loader.js b/src/lib/notification-i18n-loader.js index a61755c8..71f9156a 100644 --- a/src/lib/notification-i18n-loader.js +++ b/src/lib/notification-i18n-loader.js @@ -1,5 +1,8 @@ -// This somewhat mysterious module -module.exports = function(source) { +// This somewhat mysterious module will load a json string +// and then extract only the 'notifications' part. This is +// meant to be used to load the partial i18n we need for +// the service worker. +module.exports = function (source) { var object = JSON.parse(source) var smol = { notifications: object.notifications || {} -- cgit v1.2.3-70-g09d2