Skip to content

Commit

Permalink
Use the active pinia when manually mounting components
Browse files Browse the repository at this point in the history
Otherwise the store will be wiped out whenever we mount a component manually.
  • Loading branch information
davelopez committed Jun 4, 2024
1 parent a9c1300 commit 60d54b8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions client/src/utils/mountVueComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import BootstrapVue from "bootstrap-vue";
import { iconPlugin, localizationPlugin, vueRxShortcutPlugin } from "components/plugins";
import { createPinia, PiniaVuePlugin } from "pinia";
import { getActivePinia, PiniaVuePlugin } from "pinia";
import Vue from "vue";

// Load Pinia
Expand All @@ -22,18 +22,17 @@ Vue.use(vueRxShortcutPlugin);
// font-awesome svg icon registration/loading
Vue.use(iconPlugin);

// Create Pinia
const pinia = createPinia();

export const mountVueComponent = (ComponentDefinition) => {
const component = Vue.extend(ComponentDefinition);
const pinia = getActivePinia();
return (propsData, el) => new component({ propsData, el, pinia });
};

export const replaceChildrenWithComponent = (el, ComponentDefinition, propsData = {}) => {
const container = document.createElement("div");
el.replaceChildren(container);
const component = Vue.extend(ComponentDefinition);
const pinia = getActivePinia();
const mountFn = (propsData, el) => new component({ propsData, el, pinia });
return mountFn(propsData, container);
};

0 comments on commit 60d54b8

Please sign in to comment.