From de6d77d0cbd2905e021a075b667b6688cd5e06f6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 21 Feb 2018 15:30:03 +0900 Subject: wip --- src/web/app/common/define-widget.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/web/app/common/define-widget.ts') 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(data: { name: string; - props?: T; + props?: () => T; }) { return Vue.extend({ props: { @@ -17,20 +17,9 @@ export default function(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(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 + }); } }); } -- cgit v1.2.3-freya