refactor(fragment): add hook directly

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/888/head
Varun Patil 2023-10-24 02:38:56 -07:00
parent 9db97aed3d
commit e81e65cf7f
3 changed files with 7 additions and 13 deletions

View File

@ -67,7 +67,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import type { Route } from 'vue-router';
import NcContent from '@nextcloud/vue/dist/Components/NcContent'; import NcContent from '@nextcloud/vue/dist/Components/NcContent';
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent'; import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent';
@ -160,12 +159,6 @@ export default defineComponent({
settingsOpen: false, settingsOpen: false,
}), }),
watch: {
async $route(to: Route, from: Route) {
utils.fragment.changeTrigger(to, from);
},
},
computed: { computed: {
native(): boolean { native(): boolean {
return nativex.has(); return nativex.has();

2
src/globals.d.ts vendored
View File

@ -1,4 +1,4 @@
import Router, { Route } from 'vue-router'; import Router, { type Route } from 'vue-router';
import type { ComponentPublicInstance } from 'vue'; import type { ComponentPublicInstance } from 'vue';
import type { translate, translatePlural } from '@nextcloud/l10n'; import type { translate, translatePlural } from '@nextcloud/l10n';

View File

@ -1,4 +1,3 @@
import type { Route } from 'vue-router';
import { bus } from './event-bus'; import { bus } from './event-bus';
/** Mapping of route name to key type */ /** Mapping of route name to key type */
@ -161,13 +160,15 @@ export const fragment = {
get viewer() { get viewer() {
return this.get(FragmentType.viewer); return this.get(FragmentType.viewer);
}, },
};
document.addEventListener('DOMContentLoaded', () => {
/** /**
* Trigger when route changes. Only called by App.vue as a router hook. * Trigger when route changes; notify listeners of popped fragments.
* @param to Switching to this route * @param to Switching to this route
* @param from Switching from this route * @param from Switching from this route
*/ */
changeTrigger(to: Route, from: Route) { _m.router.afterEach((to, from) => {
const toF = decodeFragment(to.hash); const toF = decodeFragment(to.hash);
const fromF = decodeFragment(from.hash); const fromF = decodeFragment(from.hash);
@ -183,5 +184,5 @@ export const fragment = {
} }
} }
}); });
}, });
}; });