Skip to content

Commit

Permalink
Move isNuxtRendering to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MisRob committed Feb 23, 2024
1 parent 5c6c05d commit 871df7b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
9 changes: 1 addition & 8 deletions lib/composables/_useKWindowDimensions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../composition-api'; //Due to @vue/composition-api shortcomings, add plugin prior to use in kolibri, studio and tests
import { onMounted, onUnmounted, ref } from '@vue/composition-api';
import { throttle } from 'frame-throttle';
import { isNuxtServerSideRendering } from '../../utils';

/** Global variables */
export const windowWidth = ref(null);
Expand Down Expand Up @@ -30,14 +31,6 @@ function windowMetrics() {
};
}

/**
* Check if Nuxt is server side rendering
* @returns {Boolean}
*/
function isNuxtServerSideRendering() {
return process && process.server;
}

/**
* @param {CallableFunction} eventHandler - The event callback function
*/
Expand Down
14 changes: 4 additions & 10 deletions lib/composables/useKResponsiveWindow/MediaQuery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isNuxtServerSideRendering } from '../../utils';

/**
* Class representing a MediaQuery
*/
Expand All @@ -23,21 +25,13 @@ export default class MediaQuery {
return this._mediaQueryList;
}

/**
* Check if Nuxt is server side rendering
* @returns {Boolean}
*/
isNuxtServerSideRendering() {
return process && process.server;
}

/**
* Start listening for media query events
* @returns {Object} Containing mediaQueryList, eventHandler, and stopListening
*/
startListening() {
// Prevent function execution if Nuxt is server side rendering
if (this.isNuxtServerSideRendering() || !window.matchMedia) {
if (isNuxtServerSideRendering() || !window.matchMedia) {
return;
}

Expand All @@ -53,7 +47,7 @@ export default class MediaQuery {
*/
stopListening() {
// Prevent function execution if Nuxt is server side rendering
if (this.isNuxtServerSideRendering() || !window.matchMedia) {
if (isNuxtServerSideRendering() || !window.matchMedia) {
return;
}
if (this.mediaQueryList.removeEventListener) {
Expand Down
11 changes: 2 additions & 9 deletions lib/composables/useKResponsiveWindow/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, onBeforeUnmount, onMounted, ref, watch } from '@vue/composition-api';
import useKWindowDimensions, { windowWidth, windowHeight } from '../_useKWindowDimensions';
import { isNuxtServerSideRendering } from '../../utils';
import MediaQuery from './MediaQuery';

/** Global variables */
Expand Down Expand Up @@ -28,19 +29,11 @@ const heightQuery = new MediaQuery('screen and (max-height: 600px)', event => {
windowIsShort.value = event.matches;
});

/**
* Check if Nuxt is server side rendering
* @returns {Boolean}
*/
function isNuxtServerSideRendering() {
return process && process.server;
}

/**
* Initialize media query window properties
*/
function initProps() {
if (isNuxtServerSideRendering) {
if (isNuxtServerSideRendering()) {
return;
}
if (window.matchMedia) {
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Check if Nuxt is server side rendering
* @returns {Boolean}
*/
export function isNuxtServerSideRendering() {
return process && process.server;
}

0 comments on commit 871df7b

Please sign in to comment.