From 7c91da61835081f9fad4582103b6db3d8f4fe27c Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 1 Jan 2017 11:23:09 +0900 Subject: [PATCH] Refactor: Improve readability --- src/web/app/boot.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/web/app/boot.js b/src/web/app/boot.js index 612e73e88..5067600c6 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -1,13 +1,6 @@ -/* -MISSKEY BOOT LOADER - -Misskeyを起動します。 -1. 初期化 -2. ユーザー取得(ログインしていれば) -3. アプリケーションをマウント -*/ - -// LOAD DEPENDENCIES +/** + * boot + */ const riot = require('riot'); require('velocity'); @@ -18,7 +11,9 @@ const mixins = require('./common/mixins.ls'); const checkForUpdate = require('./common/scripts/check-for-update.ls'); require('./common/tags.ls'); -// MISSKEY ENTORY POINT +/** + * MISSKEY ENTORY POINT! + */ document.domain = CONFIG.host; @@ -64,26 +59,33 @@ module.exports = callback => { if (cachedMe != null) { localStorage.removeItem('me'); } + fetchme(i, false, fetched); } function fetched(me) { if (me != null) { riot.observable(me); + if (me.data.cache) { localStorage.setItem('me', JSON.stringify(me)); + me.on('updated', () => { // キャッシュ更新 localStorage.setItem('me', JSON.stringify(me)); }); } } + mixins(me); + const init = document.getElementById('init'); init.parentNode.removeChild(init); + const app = document.createElement('div'); app.setAttribute('id', 'app'); document.body.appendChild(app); + try { callback(me); } catch (e) { @@ -113,6 +115,7 @@ function fetchme(token, silent, cb) { if (res.status !== 200) { return signout(); } + res.json().then(i => { me = i; me.token = token;