wip
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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が利用できないので強制的にサインアウトさせる
|
||||
|
||||
Reference in New Issue
Block a user