Skip to content

Commit

Permalink
refactor(fragment): add hook directly
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Oct 24, 2023
1 parent 9db97ae commit e81e65c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
7 changes: 0 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

<script lang="ts">
import { defineComponent } from 'vue';
import type { Route } from 'vue-router';
import NcContent from '@nextcloud/vue/dist/Components/NcContent';
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent';
Expand Down Expand Up @@ -160,12 +159,6 @@ export default defineComponent({
settingsOpen: false,
}),
watch: {
async $route(to: Route, from: Route) {
utils.fragment.changeTrigger(to, from);
},
},
computed: {
native(): boolean {
return nativex.has();
Expand Down
2 changes: 1 addition & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Router, { Route } from 'vue-router';
import Router, { type Route } from 'vue-router';
import type { ComponentPublicInstance } from 'vue';

import type { translate, translatePlural } from '@nextcloud/l10n';
Expand Down
11 changes: 6 additions & 5 deletions src/services/utils/fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Route } from 'vue-router';
import { bus } from './event-bus';

/** Mapping of route name to key type */
Expand Down Expand Up @@ -161,13 +160,15 @@ export const fragment = {
get 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 from Switching from this route
*/
changeTrigger(to: Route, from: Route) {
_m.router.afterEach((to, from) => {
const toF = decodeFragment(to.hash);
const fromF = decodeFragment(from.hash);

Expand All @@ -183,5 +184,5 @@ export const fragment = {
}
}
});
},
};
});
});

0 comments on commit e81e65c

Please sign in to comment.