This commit simplifies event handling, providing a unified and robust
way to handle event lifecycling. This way, it fixes events not being
unsubscribed when state is changed.
Introduce a new function in `EventSubscriptionCollection` to remove
existing events and adding new events. This provides an easier to use
API, which leads to code that's easier to understand. It also prevents
potential bugs that may occur due to forgetting to call both functions.
It fixes `TheScriptsMenu` not unregistering events on state change.
Other improvements include:
- Include a getter to get total amount of registered subcriptions.
This helps in unit testing.
- Have nullish checks to prevent potential errors further down the
execution.
- Use array instead of rest parameters to increase readability and
simplify tests.
Ensure `SliderHandler` stops resizes on unmount, unsubscribing from all
events and resetting state to default.
Update `injectionKeys` to do imports as types to avoid circular
dependencies. Simplify importing `injectionKeys` to enable and strict
typings for iterating injection keys.
Add tests covering new behavior.
89 lines
2.1 KiB
Vue
89 lines
2.1 KiB
Vue
<template>
|
|
<span class="url">
|
|
<a
|
|
:href="downloadUrl"
|
|
v-bind:class="{
|
|
url__active: hasCurrentOsDesktopVersion && isCurrentOs,
|
|
url__inactive: hasCurrentOsDesktopVersion && !isCurrentOs,
|
|
}">{{ operatingSystemName }}</a>
|
|
</span>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import {
|
|
defineComponent, PropType, computed,
|
|
inject,
|
|
} from 'vue';
|
|
import { InjectionKeys } from '@/presentation/injectionSymbols';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
|
|
export default defineComponent({
|
|
props: {
|
|
operatingSystem: {
|
|
type: Number as PropType<OperatingSystem>,
|
|
required: true,
|
|
},
|
|
},
|
|
setup(props) {
|
|
const { info } = inject(InjectionKeys.useApplication);
|
|
const { os: currentOs } = inject(InjectionKeys.useRuntimeEnvironment);
|
|
|
|
const isCurrentOs = computed<boolean>(() => {
|
|
return currentOs === props.operatingSystem;
|
|
});
|
|
|
|
const operatingSystemName = computed<string>(() => {
|
|
return getOperatingSystemName(props.operatingSystem);
|
|
});
|
|
|
|
const hasCurrentOsDesktopVersion = computed<boolean>(() => {
|
|
return hasDesktopVersion(props.operatingSystem);
|
|
});
|
|
|
|
const downloadUrl = computed<string | undefined>(() => {
|
|
return info.getDownloadUrl(props.operatingSystem);
|
|
});
|
|
|
|
return {
|
|
downloadUrl,
|
|
operatingSystemName,
|
|
isCurrentOs,
|
|
hasCurrentOsDesktopVersion,
|
|
};
|
|
},
|
|
});
|
|
|
|
function hasDesktopVersion(os: OperatingSystem): boolean {
|
|
return os === OperatingSystem.Windows
|
|
|| os === OperatingSystem.Linux
|
|
|| os === OperatingSystem.macOS;
|
|
}
|
|
|
|
function getOperatingSystemName(os: OperatingSystem): string {
|
|
switch (os) {
|
|
case OperatingSystem.Linux:
|
|
return 'Linux (preview)';
|
|
case OperatingSystem.macOS:
|
|
return 'macOS';
|
|
case OperatingSystem.Windows:
|
|
return 'Windows';
|
|
default:
|
|
throw new Error(`Unsupported os: ${OperatingSystem[os]}`);
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
@use "@/presentation/assets/styles/main" as *;
|
|
.url {
|
|
@include clickable;
|
|
&__active {
|
|
font-size: 1em;
|
|
}
|
|
&__inactive {
|
|
font-size: 0.70em;
|
|
}
|
|
}
|
|
</style>
|