Skip to content

Commit

Permalink
👌 IMPROVE: use local event bus instead of component ref to pass event…
Browse files Browse the repository at this point in the history
… to child component

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
  • Loading branch information
violoncelloCH committed Nov 12, 2019
1 parent ef103eb commit 149536a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
></TextEditor>
</div>
<div class="composer-actions">
<ComposerAttachments ref="composerAttachments" v-model="attachments" @upload="onAttachmentsUploading" />
<ComposerAttachments v-model="attachments" :bus="bus" @upload="onAttachmentsUploading" />
<div class="composer-actions-right">
<p class="composer-actions-draft">
<span v-if="savingDraft === true" id="draft-status">{{ t('mail', 'Saving draft …') }}</span>
Expand Down Expand Up @@ -278,6 +278,7 @@ export default {
selectCc: this.cc,
selectBcc: this.bcc,
editorPlainText: this.isPlainText,
bus: new Vue(),
}
},
computed: {
Expand Down Expand Up @@ -358,10 +359,10 @@ export default {
this.saveDraftDebounced(this.getMessageData())
},
onAddLocalAttachment() {
this.$refs.composerAttachments.onAddLocalAttachment()
this.bus.$emit('onAddLocalAttachment')
},
onAddCloudAttachment() {
this.$refs.composerAttachments.onAddCloudAttachment()
this.bus.$emit('onAddCloudAttachment')
},
onAutocomplete(term) {
if (term === undefined || term === '') {
Expand Down
8 changes: 8 additions & 0 deletions src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default {
type: Array,
required: true,
},
bus: {
type: Object,
required: true,
},
},
data() {
return {
Expand All @@ -73,6 +77,10 @@ export default {
return ((uploaded / total) * 100).toFixed(1)
},
},
created() {
this.bus.$on('onAddLocalAttachment', this.onAddLocalAttachment)
this.bus.$on('onAddCloudAttachment', this.onAddCloudAttachment)
},
methods: {
onAddLocalAttachment() {
this.$refs.localAttachments.click()
Expand Down

0 comments on commit 149536a

Please sign in to comment.