diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-02-21 15:30:03 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-02-21 15:30:03 +0900 |
| commit | de6d77d0cbd2905e021a075b667b6688cd5e06f6 (patch) | |
| tree | 4f960a3943926295ca1017bdd1cd35bc33dfe223 /src/web/app/common | |
| parent | wip (diff) | |
| download | sharkey-de6d77d0cbd2905e021a075b667b6688cd5e06f6.tar.gz sharkey-de6d77d0cbd2905e021a075b667b6688cd5e06f6.tar.bz2 sharkey-de6d77d0cbd2905e021a075b667b6688cd5e06f6.zip | |
wip
Diffstat (limited to 'src/web/app/common')
| -rw-r--r-- | src/web/app/common/define-widget.ts | 27 | ||||
| -rw-r--r-- | src/web/app/common/mios.ts | 19 | ||||
| -rw-r--r-- | src/web/app/common/scripts/streaming/home-stream.ts | 4 |
3 files changed, 18 insertions, 32 deletions
diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts index 6088efd7e5..930a7c5868 100644 --- a/src/web/app/common/define-widget.ts +++ b/src/web/app/common/define-widget.ts @@ -2,7 +2,7 @@ import Vue from 'vue'; export default function<T extends object>(data: { name: string; - props?: T; + props?: () => T; }) { return Vue.extend({ props: { @@ -17,20 +17,9 @@ export default function<T extends object>(data: { }, data() { return { - props: data.props || {} as T + props: data.props ? data.props() : {} as T }; }, - watch: { - props(newProps, oldProps) { - if (JSON.stringify(newProps) == JSON.stringify(oldProps)) return; - (this as any).api('i/update_home', { - id: this.id, - data: newProps - }).then(() => { - (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps; - }); - } - }, created() { if (this.props) { Object.keys(this.props).forEach(prop => { @@ -39,6 +28,18 @@ export default function<T extends object>(data: { } }); } + + this.$watch('props', newProps => { + console.log(this.id, newProps); + (this as any).api('i/update_home', { + id: this.id, + data: newProps + }).then(() => { + (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps; + }); + }, { + deep: true + }); } }); } diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index c4208aa913..4b9375f548 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -1,9 +1,8 @@ import { EventEmitter } from 'eventemitter3'; -import * as riot from 'riot'; +import api from './scripts/api'; import signout from './scripts/signout'; import Progress from './scripts/loading'; import HomeStreamManager from './scripts/streaming/home-stream-manager'; -import api from './scripts/api'; import DriveStreamManager from './scripts/streaming/drive-stream-manager'; import ServerStreamManager from './scripts/streaming/server-stream-manager'; import RequestsStreamManager from './scripts/streaming/requests-stream-manager'; @@ -226,22 +225,8 @@ export default class MiOS extends EventEmitter { // フェッチが完了したとき const fetched = me => { if (me) { - riot.observable(me); - - // この me オブジェクトを更新するメソッド - me.update = data => { - if (data) Object.assign(me, data); - me.trigger('updated'); - }; - // ローカルストレージにキャッシュ localStorage.setItem('me', JSON.stringify(me)); - - // 自分の情報が更新されたとき - me.on('updated', () => { - // キャッシュ更新 - localStorage.setItem('me', JSON.stringify(me)); - }); } this.i = me; @@ -270,8 +255,6 @@ export default class MiOS extends EventEmitter { // 後から新鮮なデータをフェッチ fetchme(cachedMe.token, freshData => { Object.assign(cachedMe, freshData); - cachedMe.trigger('updated'); - cachedMe.trigger('refreshed'); }); } else { // Get token from cookie diff --git a/src/web/app/common/scripts/streaming/home-stream.ts b/src/web/app/common/scripts/streaming/home-stream.ts index 11ad754ef0..a92b61caed 100644 --- a/src/web/app/common/scripts/streaming/home-stream.ts +++ b/src/web/app/common/scripts/streaming/home-stream.ts @@ -16,7 +16,9 @@ export default class Connection extends Stream { }, 1000 * 60); // 自分の情報が更新されたとき - this.on('i_updated', me.update); + this.on('i_updated', i => { + Object.assign(me, i); + }); // トークンが再生成されたとき // このままではAPIが利用できないので強制的にサインアウトさせる |