Skip to content

Commit

Permalink
optimized track store usage
Browse files Browse the repository at this point in the history
  • Loading branch information
suterma committed Nov 15, 2024
1 parent f2ec1f5 commit f060e99
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/components/track/MediaTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ import MessageOverlay from '@/components/MessageOverlay.vue';
import { Subscription } from 'sub-events';
import { PlaybackState } from '@/code/media/PlaybackState';
import useLog from '@/composables/LogComposable';
import { createTrackStore } from '@/store/track/index';
import { useTrackStore } from '@/store/track/index';
import MeterDisplay from '@/components/displays/MeterDisplay.vue';
import ArtistDisplay from '@/components/displays/ArtistDisplay.vue';
Expand Down Expand Up @@ -851,7 +851,7 @@ const {
* @remarks Code inside the setup script runs once per component instance,
* thus the track store must be destroyed after component unload.
*/
const trackStore = createTrackStore(props.trackId);
const trackStore = useTrackStore(props.trackId);
const {
isActiveTrack,
mediaHandler,
Expand Down
4 changes: 2 additions & 2 deletions src/components/track/NoticeTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { storeToRefs } from 'pinia';
import { useAppStore } from '@/store/app';
import CloseButton from '../buttons/CloseButton.vue';
import type { ITrack } from '@/store/ITrack';
import { createTrackStore } from '@/store/track/index';
import { useTrackStore } from '@/store/track/index';
const props = defineProps({
/** The track to display
Expand All @@ -46,7 +46,7 @@ const { mediaUrls } = storeToRefs(app);
* @remarks Code inside the setup script runs once per component instance,
* thus the track store must be destroyed after component unload.
*/
const trackStore = createTrackStore(props.track.Id);
const trackStore = useTrackStore(props.track.Id);
const { mediaUrl } = storeToRefs(trackStore);
onUnmounted(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/track/PdfTrack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ import { confirm } from '@/code/ui/dialogs';
import TagInput from '@/components/editor/TagInput.vue';
import TagsDisplay from '@/components/displays/TagsDisplay.vue';
import { PlaybackState } from '@/code/media/PlaybackState';
import { createTrackStore } from '@/store/track/index';
import { useTrackStore } from '@/store/track/index';
const props = defineProps({
/** The track to display
Expand All @@ -243,7 +243,7 @@ const { showPdfInline } = storeToRefs(settings);
* @remarks Code inside the setup script runs once per component instance,
* thus the track store must be destroyed after component unload.
*/
const trackStore = createTrackStore(props.track.Id);
const trackStore = useTrackStore(props.track.Id);
const { mediaUrl } = storeToRefs(trackStore);
onUnmounted(() => {
Expand Down
13 changes: 3 additions & 10 deletions src/components/track/TrackHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ import BaseIcon from '@/components/icons/BaseIcon.vue';
import { playbackStateInjectionKey } from './TrackInjectionKeys';
import { useSettingsStore } from '@/store/settings';
import { storeToRefs } from 'pinia';
import { createTrackStore } from '@/store/track/index';
import { useTrackStore } from '@/store/track/index';
import { PlaybackState } from '@/code/media/PlaybackState';
import FileHandler from '@/store/filehandler';
Expand Down Expand Up @@ -302,11 +302,8 @@ const props = defineProps({
// --- tracking the associated ITrack
/** The dynamic track store for this component.
* @remarks Code inside the setup script runs once per component instance,
* thus the track store must be destroyed after component unload.
*/
const trackStore = createTrackStore(props.trackId);
/** The dynamic track store for this component. */
const trackStore = useTrackStore(props.trackId);
const {
useMeasureNumbers,
track,
Expand All @@ -320,10 +317,6 @@ const {
preRollDuration,
} = storeToRefs(trackStore);
onUnmounted(() => {
trackStore.$dispose();
});
const app = useAppStore();
const { isTrackEditable } = storeToRefs(app);
Expand Down
29 changes: 6 additions & 23 deletions src/components/track/TrackTitle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}"
:name="name"
>

</TrackTitleName>

<!-- <span
Expand All @@ -29,19 +28,13 @@
</i>
</span> -->

<span
v-if="artist || album || meter"
class='is-hidden-mobile'
>
<span v-if="artist || album || meter" class="is-hidden-mobile">
<ArtistDisplay
class="mr-2 is-size-7"
:artist="artist"
:album="album"
/>
<MeterDisplay
class="mr-2 is-size-7"
:meter="meter"
></MeterDisplay>
<MeterDisplay class="mr-2 is-size-7" :meter="meter"></MeterDisplay>
</span>

<TagsDisplay
Expand All @@ -54,17 +47,14 @@
</div>
</template>

<script
setup
lang="ts"
>
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { computed, onUnmounted } from 'vue';
import TrackTitleName from '@/components/track/TrackTitleName.vue';
import MeterDisplay from '@/components/displays/MeterDisplay.vue';
import ArtistDisplay from '@/components/displays/ArtistDisplay.vue';
import TagsDisplay from '@/components/displays/TagsDisplay.vue';
import { createTrackStore } from '@/store/track/index';
import { useTrackStore } from '@/store/track/index';
import NavButton from '@/components/buttons/NavButton.vue';
import { mdiDotsVertical } from '@mdi/js';
Expand Down Expand Up @@ -104,11 +94,8 @@ const props = defineProps({
// --- tracking the associated ITrack
/** The dynamic track store for this component.
* @remarks Code inside the setup script runs once per component instance,
* thus the track store must be destroyed after component unload.
*/
const trackStore = createTrackStore(props.trackId);
/** The dynamic track store for this component. */
const trackStore = useTrackStore(props.trackId);
const {
isActiveTrack,
meter,
Expand All @@ -119,10 +106,6 @@ const {
album,
} = storeToRefs(trackStore);
onUnmounted(() => {
trackStore.$dispose();
});
// const tooltipText = computed(() => {
// const artistLabel = artist.value ? "by " + artist.value + " " : "";
// const albumLabel = album.value ? "on " + album.value + " " : "";
Expand Down
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ export enum Store {
Audio = 'AUDIO',
/** A store for multitrack audio-related global state */
Multitrack = 'MULTITRACK',
/** A store for track-related state, for a single track */
Track = 'TRACK',
}
8 changes: 5 additions & 3 deletions src/store/track/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import CompilationHandler from '../compilation-handler';
import FileHandler from '../filehandler';
import { Meter } from '@/code/music/Meter';
import { useSettingsStore } from '../settings';
import { Store } from '..';

// export factory function
export function createTrackStore(trackId: string) {
return defineStore(`tracks/${trackId}`, () => {
/** A factory function for a single track store */
export function useTrackStore(trackId: string) {
/** A dynamic store for holding data for a single track */
return defineStore(`${Store.Track}/${trackId}`, () => {
const app = useAppStore();
const settings = useSettingsStore();
const audio = useAudioStore();
Expand Down

0 comments on commit f060e99

Please sign in to comment.