Skip to content

Convert store.ts into multiple Pinia stores #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Conversation

jjnesbitt
Copy link
Member

This PR converts our use of global store via vue refs, to instead use pinia stores. These stores allow better organization, and makes it easier to track what state is used and where.

Since this is a large change, I recommend going through the commits one at a time. I structured them in a well scoped way. It's possible that there are still some rough edges, as I tried to mainly focus on keeping this PR scoped to reorganization, rather than lower level refactoring.

@jjnesbitt jjnesbitt requested a review from annehaley May 15, 2025 20:18
@jjnesbitt jjnesbitt changed the title Convert app store into multiple Pinia stores Convert store.ts into multiple Pinia stores May 15, 2025
Copy link
Collaborator

@annehaley annehaley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean about the organization Pinia provides. I like the separation of concerns with this structure. I just have some general questions and a few type errors.

const activateColor = "#008837";

const map = mapStore.getMap();
map.getLayersOrder().forEach((mapLayerId) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a typescript error for mapLayerId implicitly having an any type here, as well as in a handful of other places (all errors in attached txt file)
pinia-store-typescript-errors.txt

let xmin, xmax, ymin, ymax, srs = undefined;
if (currentFrame.raster) {
const bounds = currentFrame.raster.metadata.bounds;
({ xmin, xmax, ymin, ymax, srs } = bounds);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a typescript error Type 'string' is not assignable to type 'undefined'. for the assignment of srs here

const currentStyle = styleStore.selectedLayerStyles[styleId];
currentStyle.visible = layer.visible

// TODO: Move this conditional functionality into `addLayer`, and directly call addLayerFrameToMap there
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO intentionally left for future work?

Comment on lines +85 to +95
// Must pass actual network object into setNetworkDeactivatedNodes, not computed prop
// TODO: Fix in the store function itself
if (networkStore.currentNetwork) {
selectedNodes.value = []
setNetworkDeactivatedNodes(currentNetwork.value, [])
networkStore.setNetworkDeactivatedNodes(networkStore.currentNetwork, [])
}
}

function toggleSelected() {
if (currentNetwork.value) {
// Must pass actual network object into setNetworkDeactivatedNodes, not computed prop
// TODO: Fix in the store function itself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these TODOs intentionally left for future work?

Comment on lines +5 to +9
import { useLayerStore, useNetworkStore, useStyleStore } from "@/store";

const networkStore = useNetworkStore();
const layerStore = useLayerStore();
const styleStore = useStyleStore();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how in this file, the calls of all the "use store" functions are directly below the import of those functions. Could we do it consistently like this in all the other files? I think it makes it easier to read and understand what's going on.

Comment on lines +35 to +37
loadingCharts,
availableCharts,
currentChart,
Copy link
Collaborator

@annehaley annehaley May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why charts are rolled into the analysis store instead of on their own. Is this just for consolidation of what might have been two very sparse stores?

Comment on lines +14 to +15
const rasterTooltipDataCache = computed(() => layerStore.rasterTooltipDataCache);
const clickedFeature = computed(() => mapStore.clickedFeature);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make these computed variables? Why not just refer to the store when accessing these variables? (Same goes for selectedLayers further down)

Comment on lines +23 to +30
export const useProjectStore = defineStore('project', () => {
const networkStore = useNetworkStore();
const analysisStore = useAnalysisStore();
const mapStore = useMapStore();
const layerStore = useLayerStore();
const panelStore = usePanelStore();
const appStore = useAppStore();
const styleStore = useStyleStore();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a concern of a circular-import sort of problem when you need to reference other stores in a store like this? Is there a hierarchy of which stores are loaded first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants