Skip to content

Commit

Permalink
Merge pull request galaxyproject#18299 from guerler/load_pinia_manual…
Browse files Browse the repository at this point in the history
…_mount

[24.1] Adds pinia to manually mounted vue components
  • Loading branch information
mvdbeek authored Jun 3, 2024
2 parents 60fbf43 + 85951cd commit 2c4ad24
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client/src/utils/mountVueComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

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

// Load Pinia
Vue.use(PiniaVuePlugin);

// Bootstrap components
Vue.use(BootstrapVue);

Expand All @@ -18,15 +22,18 @@ 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);
return (propsData, el) => new component({ propsData, el });
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 mountFn = (propsData, el) => new component({ propsData, el });
const mountFn = (propsData, el) => new component({ propsData, el, pinia });
return mountFn(propsData, container);
};

0 comments on commit 2c4ad24

Please sign in to comment.