Refactor: Improve readability

This commit is contained in:
syuilo 2017-01-01 11:23:09 +09:00
parent 3edd41b97e
commit 7c91da6183

View File

@ -1,14 +1,7 @@
/*
MISSKEY BOOT LOADER
Misskeyを起動します
1. 初期化
2. ユーザー取得(ログインしていれば)
3. アプリケーションをマウント
/**
* boot
*/
// LOAD DEPENDENCIES
const riot = require('riot');
require('velocity');
const api = require('./common/scripts/api.ls');
@ -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;