fix(history-queries): ensuring history-queries x-module registration before using components #1512
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Precedents
xComponentMixin(historyQueriesXModule)
mixin is executed as soon as the component is imported, before mounting it.useRegisterXModule(historyQueriesXModule)
composable is executed once the component is mounted.v-if
). So using the composable, theXModule
has not been registered when the check is executed because the component has not been mounted yet.How can we ensure the
XModule
registration?Registering it as soon as we can, in the
XModule
creation itself.Key concepts to understand why it works
XModule
to assign thexModule
name to itself.Workflow example
xModule
component:import { HistoryQueries } from '@empathyco/x-components/history-queries';
HistoryQueries
component imports the moduleimport { historyQueriesXModule } from '../x-module'
to assign thexModule
name to the componentxModule: historyQueriesXModule.name
xModule
JS file, we register the component itself after creating itXPlugin.registerXModule(historyQueriesXModule);
xModule
is imported (with the mixin or composable, the registration was tried once per component)tl;dr
xModule
registration now is done at the same time an X component is imported, and we can guarantee the store module is registered before mounting the component.We just need to remember to assign the
xModule
name to each x-componentxModule: historyQueriesXModule.name