Skip to content

Commit

Permalink
feat: make options reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
NetCZ committed May 28, 2020
1 parent 758ac2b commit a2546f1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/component.js
Expand Up @@ -63,13 +63,15 @@ export default {
},
defaultOptions: {
format: 'D MMM YYYY'
},
mergedOptions: {}
}
};
},
computed: {
elementAttributes(): Object {
return Object.assign({}, this.$attrs, this.elAttrs);
},
mergedOptions() {
return Object.assign({}, this.defaultOptions, this.options);
}
},
render(h: Function): Object {
Expand All @@ -79,9 +81,6 @@ export default {
value: this.inputValue(this.value)
}, this.$slots.default);
},
beforeMount() {
this.mergedOptions = Object.assign({}, this.defaultOptions, this.options);
},
mounted() {
this.create();

Expand All @@ -98,6 +97,14 @@ export default {
beforeDestroy() {
this.destroy();
},
watch: {
options: {
handler() {
this.reload();
},
deep: true
}
},
methods: {
create() {
this.mergedOptions.field = this.$el;
Expand Down Expand Up @@ -126,6 +133,10 @@ export default {
destroy() {
this.pikaday.destroy();
},
reload() {
this.destroy();
this.create();
},
change(value: typeof undefined | null | Date) {
this.$emit('input', value);
this.$emit('input-value', this.inputValue(value));
Expand Down

0 comments on commit a2546f1

Please sign in to comment.