Skip to content

Commit

Permalink
feat: migrate component & xmodule register
Browse files Browse the repository at this point in the history
  • Loading branch information
annacv committed Jun 19, 2024
1 parent b4c5f7b commit 84e2691
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
<script lang="ts">
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import { XOn } from '../../../components/decorators/bus.decorators';
import { defineComponent } from 'vue';
import { XEvent, XEventsTypes } from '../../../wiring/events.types';
import { xComponentMixin } from '../../../components/x-component.mixin';
import { experienceControlsXModule } from '../x-module';
import { useNoElementRender, useXBus } from '../../../composables';
/**
* This component subscribes to changes in the ExperienceControls module to fire the events that
* propagate the configuration.
*
* @public
*/
@Component({
mixins: [xComponentMixin(experienceControlsXModule)]
})
export default class ExperienceControls extends Vue {
/**.
* Iterates the list of XEvents received and emits them
*
* @param events - events to be emitted
*/
@XOn('ExperienceControlsEventsChanged')
onEventsChanged(events: Partial<XEventsTypes>): void {
Object.entries(events).forEach(([eventName, eventPayload]) => {
this.$x.emit(eventName as XEvent, eventPayload);
});
}
export default defineComponent({
name: 'ExperienceControls',
xModule: experienceControlsXModule.name,
setup(_, { slots }) {
const xBus = useXBus();
/**
* Iterates the list of XEvents received and emits them.
*
* @param events - Events to be emitted.
*/
function onEventsChanged(events: Partial<XEventsTypes>): void {
Object.entries(events).forEach(([eventName, eventPayload]) => {
xBus.emit(eventName as XEvent, eventPayload);
});
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
render(): void {}
}
xBus.on('ExperienceControlsEventsChanged', false).subscribe(event => onEventsChanged(event));
return () => useNoElementRender(slots);
}
});
</script>

<docs lang="mdx">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { XModule } from '../x-modules.types';
import { XPlugin } from '../../plugins/index';
import { experienceControlsEmitters } from './store/emitters';
import { experienceControlsXStoreModule } from './store/module';
import { ExperienceControlsXStoreModule } from './store/types';
Expand All @@ -23,3 +24,5 @@ export const experienceControlsXModule: ExperienceControlsXModule = {
storeEmitters: experienceControlsEmitters,
wiring: experienceControlsWiring
};

XPlugin.registerXModule(experienceControlsXModule);

0 comments on commit 84e2691

Please sign in to comment.