From 793dfb4f420b6d52fe8a510ff726d3830d20c702 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Thu, 13 Dec 2018 11:12:06 -0800 Subject: [PATCH] initial state refactor --- app/capabilities.js | 2 +- app/main.js | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/capabilities.js b/app/capabilities.js index 76a2d8c1..b6cba361 100644 --- a/app/capabilities.js +++ b/app/capabilities.js @@ -74,7 +74,7 @@ async function polyfillStreams() { } } -export default async function capabilities() { +export default async function getCapabilities() { const serviceWorker = 'serviceWorker' in navigator; let crypto = await checkCrypto(); const nativeStreams = checkStreams(); diff --git a/app/main.js b/app/main.js index 3f11594a..be0d6cb8 100644 --- a/app/main.js +++ b/app/main.js @@ -5,7 +5,7 @@ import 'fluent-intl-polyfill'; import choo from 'choo'; import nanotiming from 'nanotiming'; import routes from './routes'; -import capabilities from './capabilities'; +import getCapabilities from './capabilities'; import controller from './controller'; import dragManager from './dragManager'; import pasteManager from './pasteManager'; @@ -26,23 +26,25 @@ if (process.env.NODE_ENV === 'production') { } (async function start() { - const app = routes(choo()); - const capa = await capabilities(); - if (capa.serviceWorker) { + const capabilities = await getCapabilities(); + if (capabilities.serviceWorker) { await navigator.serviceWorker.register('/serviceWorker.js'); await navigator.serviceWorker.ready; } const translate = await getTranslator(LOCALE); + window.initialState = { + capabilities, + translate, + storage, + raven: Raven, + user: new User(storage), + transfer: null, + fileInfo: null + }; + const app = routes(choo()); app.use((state, emitter) => { - state.capabilities = capa; - state.transfer = null; - state.fileInfo = null; - state.translate = translate; - state.storage = storage; - state.raven = Raven; - state.user = new User(storage); window.appState = state; window.appEmit = emitter.emit.bind(emitter); let unsupportedReason = null;