Skip to content

Commit

Permalink
Merge pull request #3766 from nextcloud/chore/vue3/migrate-event-buse…
Browse files Browse the repository at this point in the history
…s-to-mitt

chore(vue3): migrate event buses to mitt
  • Loading branch information
ChristophWurst authored Jan 3, 2024
2 parents ebe8c80 + 045ede5 commit 0195719
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"debounce": "^1.2.1",
"downloadjs": "^1.4.7",
"ical.js": "^1.5.0",
"mitt": "^3.0.1",
"moment": "^2.29.4",
"p-limit": "^4.0.0",
"qr-image": "^3.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/AppContent/ContactsContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import ContactDetails from '../ContactDetails.vue'
import ContactsList from '../ContactsList.vue'
import IconContact from 'vue-material-design-icons/AccountMultiple.vue'
import RouterMixin from '../../mixins/RouterMixin.js'
import Vue from 'vue'
import mitt from 'mitt'

export default {
name: 'ContactsContent',
Expand Down Expand Up @@ -117,7 +117,7 @@ export default {
return {
searchQuery: '',
// communication for ContactListItem and ContactDetails (reload avatar)
reloadBus: new Vue(),
reloadBus: mitt(),
}
},

Expand Down
4 changes: 2 additions & 2 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ import { showError } from '@nextcloud/dialogs'

import { stringify } from 'ical.js'
import qr from 'qr-image'
import Vue from 'vue'
import mitt from 'mitt'
import {
NcActions as Actions,
NcActionButton as ActionButton,
Expand Down Expand Up @@ -500,7 +500,7 @@ export default {
excludeFromBirthdayKey: 'x-nc-exclude-from-birthday-calendar',

// communication for ContactDetailsAddNewProp and ContactDetailsProperty
bus: new Vue(),
bus: mitt(),
showMenuPopover: false,
profileEnabled,
isTalkEnabled,
Expand Down
8 changes: 4 additions & 4 deletions src/components/ContactDetails/ContactDetailsAddNewProp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ export default {
},

created() {
this.bus.$on('add-prop', this.addProp)
this.bus.on('add-prop', this.addProp)
},

destroyed() {
this.bus.$off('add-prop', this.addProp)
this.bus.off('add-prop', this.addProp)
},

methods: {
Expand All @@ -210,7 +210,7 @@ export default {
*/
async addProp(id) {
if (this.usedProperties.includes(id) && !this.properties[id].multiple) {
this.bus.$emit('focus-prop', id)
this.bus.emit('focus-prop', id)
return
}

Expand Down Expand Up @@ -240,7 +240,7 @@ export default {
}
}
this.moreActionsOpen = false
this.bus.$emit('focus-prop', id)
this.bus.emit('focus-prop', id)
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ContactDetails/ContactDetailsAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export default {

await this.loadPhotoUrl()

await this.reloadBus.$emit('reload-avatar', this.contact.key)
await this.reloadBus.emit('reload-avatar', this.contact.key)

this.loading = false
},
Expand Down Expand Up @@ -438,7 +438,7 @@ export default {
this.$store.dispatch('updateContact', this.contact)
// somehow the avatarUrl is not unavailable immediately, so we just set undefined
this.photoUrl = undefined
this.reloadBus.$emit('delete-avatar', this.contact.key)
this.reloadBus.emit('delete-avatar', this.contact.key)
},

/**
Expand Down Expand Up @@ -530,7 +530,7 @@ export default {

await this.loadPhotoUrl()

await this.reloadBus.$emit('reload-avatar', this.contact.key)
await this.reloadBus.emit('reload-avatar', this.contact.key)

// Notify user
showSuccess(t('contacts', 'Avatar downloaded from social network'))
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContactDetails/ContactDetailsProperty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ export default {
},

created() {
this.bus.$on('focus-prop', this.onFocusProp)
this.bus.on('focus-prop', this.onFocusProp)
},

destroyed() {
this.bus.$off('focus-prop', this.onFocusProp)
this.bus.off('focus-prop', this.onFocusProp)
},

methods: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/ContactsList/ContactsListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export default {
},
created() {
this.reloadBus.$on('reload-avatar', this.reloadAvatarUrl)
this.reloadBus.$on('delete-avatar', this.deleteAvatar)
this.reloadBus.on('reload-avatar', this.reloadAvatarUrl)
this.reloadBus.on('delete-avatar', this.deleteAvatar)
},
destroyed() {
this.reloadBus.$off('reload-avatar', this.reloadAvatarUrl)
this.reloadBus.$off('delete-avatar', this.deleteAvatar)
this.reloadBus.off('reload-avatar', this.reloadAvatarUrl)
this.reloadBus.off('delete-avatar', this.deleteAvatar)
},
async mounted() {
await this.loadAvatarUrl()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Properties/PropertyTitle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default {
* @param {string} id type of prop
*/
onAddProp(id) {
this.bus.$emit('add-prop', id)
this.bus.emit('add-prop', id)
},
},
}
Expand Down

0 comments on commit 0195719

Please sign in to comment.