Skip to content

Commit 34abc7d

Browse files
committed
Add pinia to build externals. Pass WWT engine store as a prop to HUD. Is there a better solution?
1 parent ffd7b14 commit 34abc7d

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/components/WwtHud.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,10 @@
3636
<script setup lang="ts">
3737
import { computed } from "vue";
3838
import { Settings } from "@wwtelescope/engine";
39-
import { engineStore } from "@wwtelescope/engine-pinia";
4039
import { storeToRefs } from "pinia";
4140
4241
import { WwtHUDProps } from "../types";
4342
44-
const store = engineStore();
45-
const {
46-
raRad,
47-
decRad,
48-
rollRad,
49-
zoomDeg,
50-
currentTime,
51-
clockRate,
52-
foregroundOpacity,
53-
backgroundImageset,
54-
foregroundImageset,
55-
} = storeToRefs(store);
5643
5744
const R2D = 180 / Math.PI;
5845
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -68,6 +55,26 @@ const props = withDefaults(defineProps<WwtHUDProps>(), {
6855
textShadow: "0 0 5px black",
6956
});
7057
58+
/*
59+
* I really don't care for passing the store as a prop,
60+
* but without just calling `engineStore` (or even `engineStore(wwtPinia)`),
61+
* we were getting a different store instance than in the using downstream app.
62+
* Note that if this component is placed directly in the downstream app package,
63+
* everything worked exactly as expected, so this some sort of Pinia configuration issue.
64+
* This works, so until I figure out the "right" approach, we'll just do this.
65+
*/
66+
const {
67+
raRad,
68+
decRad,
69+
rollRad,
70+
zoomDeg,
71+
currentTime,
72+
clockRate,
73+
foregroundOpacity,
74+
backgroundImageset,
75+
foregroundImageset,
76+
} = storeToRefs(props.store);
77+
7178
const cssVars = computed(() => {
7279
return {
7380
"--hud-top": props.location.top ?? "auto",

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
22
import { CircleMarkerOptions, TileLayerOptions } from "leaflet";
3+
import { engineStore } from "@wwtelescope/engine-pinia";
4+
5+
export type WWTEngineStore = ReturnType<typeof engineStore>;
36

47
/* Funding acknowledgement */
58

@@ -142,4 +145,5 @@ export interface WwtHUDProps {
142145
fontSize?: string;
143146
backgroundColor?: string | null;
144147
textShadow?: string | null;
148+
store: ReturnType<typeof engineStore>;
145149
}

vue.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = defineConfig({
3232
'commonjs2': '@wwtelescope/engine', // typeof exports === 'object' && typeof module === 'object'
3333
'commonjs': '@wwtelescope/engine', // typeof exports === 'object'
3434
'root': 'wwtlib' // none of the above: browser mode using global variables
35-
}
35+
},
36+
pinia: 'pinia',
3637
});
3738

3839
},

0 commit comments

Comments
 (0)