diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-01-30 04:37:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-30 04:37:25 +0900 |
| commit | f6154dc0af1a0d65819e87240f4385f9573095cb (patch) | |
| tree | 699a5ca07d6727b7f8497d4769f25d6d62f94b5a /src/client/widgets/define.ts | |
| parent | Add Event activity-type support (#5785) (diff) | |
| download | misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.tar.gz misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.tar.bz2 misskey-f6154dc0af1a0d65819e87240f4385f9573095cb.zip | |
v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
Diffstat (limited to 'src/client/widgets/define.ts')
| -rw-r--r-- | src/client/widgets/define.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/client/widgets/define.ts b/src/client/widgets/define.ts new file mode 100644 index 0000000000..768446c128 --- /dev/null +++ b/src/client/widgets/define.ts @@ -0,0 +1,58 @@ +import Vue from 'vue'; + +export default function <T extends object>(data: { + name: string; + props?: () => T; +}) { + return Vue.extend({ + props: { + widget: { + type: Object + }, + isCustomizeMode: { + type: Boolean, + default: false + } + }, + + computed: { + id(): string { + return this.widget.id; + }, + + props(): T { + return this.widget.data; + } + }, + + data() { + return { + bakedOldProps: null + }; + }, + + created() { + this.mergeProps(); + + this.$watch('props', () => { + this.mergeProps(); + }); + }, + + methods: { + mergeProps() { + if (data.props) { + const defaultProps = data.props(); + for (const prop of Object.keys(defaultProps)) { + if (this.props.hasOwnProperty(prop)) continue; + Vue.set(this.props, prop, defaultProps[prop]); + } + } + }, + + save() { + this.$store.dispatch('settings/updateWidget', this.widget); + } + } + }); +} |