Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 11, 2024
1 parent 2d00667 commit e589872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('WtNotificationsBar', () => {
const wrapper = shallowMount(WtNotificationsBar, {
global: { provide: { $eventBus: eventBus } },
});
wrapper.vm.$eventBus.$emit('notification', {
eventBus.$emit('notification', {
type: 'error',
text: 'error',
});
Expand All @@ -27,7 +27,7 @@ describe('WtNotificationsBar', () => {
const wrapper = shallowMount(WtNotificationsBar, {
global: { provide: { $eventBus: eventBus } },
});
wrapper.vm.$eventBus.$emit('notification', {
eventBus.$emit('notification', {
type: 'error',
text: 'error',
});
Expand All @@ -42,7 +42,7 @@ describe('WtNotificationsBar', () => {
global: { provide: { $eventBus: eventBus } },
data: () => ({ notificationDuration: 100 }),
});
wrapper.vm.$eventBus.$emit('notification', {
eventBus.$emit('notification', {
type: 'error',
text: 'error',
});
Expand Down
17 changes: 12 additions & 5 deletions src/components/wt-notifications-bar/wt-notifications-bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@
</template>

<script>
import defaultEventBus from '../../scripts/eventBus.js';
import { _wtUiLog as loggr } from '../../scripts/logger.js';
export default {
name: 'WtNotificationsBar',
inject: ['$eventBus'],
data: () => ({
notificationDuration: 4000,
notifications: [],
eventBus: defaultEventBus,
}),
created() {
try {
this.$eventBus.$on('notification', this.showNotification);
} catch (err) {
console.error('wt-notifications-bar cannot work without globally registered eventBus', err);
if (this.$eventBus) {
this.eventBus = this.$eventBus;
} else {
loggr.warn({ entity: 'component', module: 'wt-notification-bar' })('no globally provided $eventBus found, using default webitel-ui eventBus');
}
this.eventBus.$on('notification', this.showNotification);
},
unmounted() {
this.$eventBus.$off('notification', this.showNotification);
this.eventBus.$off('notification', this.showNotification);
},
methods: {
showNotification(notification) {
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import eventBus from './scripts/eventBus';
import './assets/icons/sprite';

import './css/styleguide/fonts/_fonts.scss';
import { wtlog } from './scripts/logger.js';
import App from './the-app.vue';

const app = createApp(App).use(router).use(i18n).provide('$eventBus', eventBus);
Expand Down

0 comments on commit e589872

Please sign in to comment.