diff --git a/src/renderer/utils/autobind.ts b/src/common/utils/autobind.ts similarity index 100% rename from src/renderer/utils/autobind.ts rename to src/common/utils/autobind.ts diff --git a/src/common/utils/debouncePromise.ts b/src/common/utils/debouncePromise.ts new file mode 100755 index 0000000000..22ffd5217f --- /dev/null +++ b/src/common/utils/debouncePromise.ts @@ -0,0 +1,9 @@ +// Debouncing promise evaluation + +export function debouncePromise(func: (...args: F) => T | Promise, timeout = 0): (...args: F) => Promise { + let timer: NodeJS.Timeout; + return (...params: any[]) => new Promise((resolve, reject) => { + clearTimeout(timer); + timer = setTimeout(() => resolve(func.apply(this, params)), timeout); + }); +} diff --git a/src/common/utils/index.ts b/src/common/utils/index.ts index 580a8f15c2..db46a37d97 100644 --- a/src/common/utils/index.ts +++ b/src/common/utils/index.ts @@ -1,7 +1,14 @@ -// Common utils (main/renderer) +// Common utils (main OR renderer) +export * from "./app-version" +export * from "./autobind" export * from "./base64" export * from "./camelCase" -export * from "./splitArray" -export * from "./getRandId" +export * from "./cloneJson" +export * from "./debouncePromise" +export * from "./defineGlobal" +export * from "./getRandId" +export * from "./splitArray" +export * from "./saveToAppFiles" +export * from "./singleton" export * from "./cloneJson" diff --git a/src/renderer/api/api-manager.ts b/src/renderer/api/api-manager.ts index 22735c3c09..e4a5432965 100644 --- a/src/renderer/api/api-manager.ts +++ b/src/renderer/api/api-manager.ts @@ -3,7 +3,7 @@ import type { KubeObjectDetailsProps, KubeObjectListLayoutProps, KubeObjectMenuP import type React from "react"; import { observable } from "mobx"; -import { autobind } from "../utils/autobind"; +import { autobind } from "../utils"; import { KubeApi } from "./kube-api"; export interface ApiComponents { diff --git a/src/renderer/components/dock/terminal.ts b/src/renderer/components/dock/terminal.ts index cea1e91292..e508cc22b2 100644 --- a/src/renderer/components/dock/terminal.ts +++ b/src/renderer/components/dock/terminal.ts @@ -5,7 +5,7 @@ import { FitAddon } from "xterm-addon-fit"; import { dockStore, TabId } from "./dock.store"; import { TerminalApi } from "../../api/terminal-api"; import { themeStore } from "../../theme.store"; -import { autobind } from "../../utils/autobind"; +import { autobind } from "../../utils"; export class Terminal { static spawningPool: HTMLElement; diff --git a/src/renderer/theme.store.ts b/src/renderer/theme.store.ts index 5245d2a728..539be6651d 100644 --- a/src/renderer/theme.store.ts +++ b/src/renderer/theme.store.ts @@ -1,5 +1,5 @@ import { computed, observable, reaction } from "mobx"; -import { autobind } from "./utils/autobind"; +import { autobind } from "./utils"; import { userStore } from "../common/user-store"; import logger from "../main/logger"; diff --git a/src/renderer/utils/debouncePromise.ts b/src/renderer/utils/debouncePromise.ts deleted file mode 100755 index 4ce949a944..0000000000 --- a/src/renderer/utils/debouncePromise.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Debouncing promise evaluation - -export const debouncePromise = function (promisedFunc: Function, timeout = 0) { - let timer: number; - return (...params: any[]) => new Promise((resolve, reject) => { - clearTimeout(timer); - timer = window.setTimeout(() => resolve(promisedFunc.apply(this, params)), timeout); - }); -}; diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index 578ec5c355..4ae9b068a7 100755 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -3,21 +3,18 @@ export const noop: any = Function(); export const isElectron = !!navigator.userAgent.match(/Electron/); -export * from '../../common/utils/camelCase' -export * from '../../common/utils/base64' +export * from "../../common/utils" -export * from './autobind' -export * from './cssVar' -export * from './cssNames' -export * from './eventEmitter' -export * from './downloadFile' -export * from './prevDefault' -export * from './createStorage' -export * from './interval' -export * from './debouncePromise' -export * from './copyToClipboard' -export * from './formatDuration' -export * from './isReactNode' -export * from './convertMemory' -export * from './convertCpu' -export * from './metricUnitsToNumber' +export * from "./cssVar" +export * from "./cssNames" +export * from "./eventEmitter" +export * from "./downloadFile" +export * from "./prevDefault" +export * from "./createStorage" +export * from "./interval" +export * from "./copyToClipboard" +export * from "./formatDuration" +export * from "./isReactNode" +export * from "./convertMemory" +export * from "./convertCpu" +export * from "./metricUnitsToNumber"