Skip to content

Commit

Permalink
Adds use composition-api to composable due to @vue/composition-api sh…
Browse files Browse the repository at this point in the history
…ortcomings in vue2
  • Loading branch information
akolson committed Oct 10, 2022
1 parent 4075c57 commit b16c125
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/composition-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';

Vue.use(VueCompositionAPI);
26 changes: 14 additions & 12 deletions lib/useKWindowDimensions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import './composition-api'; //Due to @vue/composition-api shortcomings, add plugin prior to use in kolibri, studio and tests
import { onBeforeUnmount, onMounted, ref } from '@vue/composition-api';

/** Window dimensions */
const windowWidth = ref(null);
const windowHeight = ref(null);

/**
* Update window width and height
*/
const updateWindow = () => {
const metrics = windowMetrics();
windowWidth.value = metrics.width;
windowHeight.value = metrics.height;
};

/**
* Returns window inner width and height
* @returns {Object} The window's inner width and height
Expand Down Expand Up @@ -44,18 +58,6 @@ function removeWindowListener(handler) {
}

export default function useKWindowDimensions() {
const windowWidth = ref(null);
const windowHeight = ref(null);

/**
* Update window width and height
*/
const updateWindow = () => {
const metrics = windowMetrics();
windowWidth.value = metrics.width;
windowHeight.value = metrics.height;
};

onMounted(() => {
addWindowListener(updateWindow);
});
Expand Down

0 comments on commit b16c125

Please sign in to comment.