Prefer JS function over arrow functions (#8307)

* Prefer JS function over arrow functions

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Nigel Breslaw 2025-04-30 11:08:49 +03:00 committed by GitHub
parent def8adf618
commit 97e490381f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 32 deletions

View file

@ -5,25 +5,25 @@ import type { Message, PluginMessageEvent } from "../../src/globals";
import type { EventTS } from "../../shared/universals";
import { generateSlintSnippet } from "./property-parsing.js";
export const dispatch = (data: any, origin = "*") => {
export function dispatch(data: any, origin = "*") {
figma.ui.postMessage(data, {
origin,
});
};
}
export const dispatchTS = <Key extends keyof EventTS>(
export function dispatchTS<Key extends keyof EventTS>(
event: Key,
data: EventTS[Key],
origin = "*",
) => {
) {
dispatch({ type: event, ...data }, origin);
};
}
export const listenTS = <Key extends keyof EventTS>(
export function listenTS<Key extends keyof EventTS>(
eventName: Key,
callback: (data: EventTS[Key] & { type: Key }) => any,
listenOnce = false,
) => {
) {
const func = (pluginMessage: any) => {
if (pluginMessage && pluginMessage.type === eventName) {
callback(pluginMessage);
@ -34,12 +34,13 @@ export const listenTS = <Key extends keyof EventTS>(
};
figma.ui.on("message", func);
};
export const getStore = async (key: string) => {
}
export async function getStore(key: string) {
const value = await figma.clientStorage.getAsync(key);
return value;
};
}
export const setStore = async (key: string, value: string) => {
export async function setStore(key: string, value: string) {
await figma.clientStorage.setAsync(key, value);
};
}

View file

@ -21,7 +21,7 @@ import OnigurumaEngine from "shiki/wasm";
import slintLang from "../../../../editors/vscode/slint.tmLanguage.json";
let highlighter: HighlighterCore | null = null;
const initHighlighter = async () => {
async function initHighlighter() {
highlighter = await createHighlighterCore({
themes: [
darkSlint as ThemeRegistration,
@ -30,7 +30,7 @@ const initHighlighter = async () => {
langs: [slintLang as LanguageRegistration],
engine: createOnigurumaEngine(OnigurumaEngine),
});
};
}
type HighlightTheme = "dark-slint" | "light-slint";

View file

@ -5,28 +5,28 @@ import { manifest } from "../../figma.config";
import type { Message, PluginMessageEvent } from "../globals";
import type { EventTS } from "../../shared/universals";
export const dispatch = (msg: Message, global = false, origin = "*") => {
export function dispatch(msg: Message, global = false, origin = "*") {
const data: PluginMessageEvent = { pluginMessage: msg };
if (!global) {
data.pluginId = manifest.id;
}
parent.postMessage(data, origin);
};
}
export const dispatchTS = <Key extends keyof EventTS>(
export function dispatchTS<Key extends keyof EventTS>(
event: Key, // Parameter name is 'event'
data: EventTS[Key],
global = false,
origin = "*",
) => {
) {
dispatch({ type: event, ...data }, global, origin);
};
}
export const listenTS = <Key extends keyof EventTS>(
export function listenTS<Key extends keyof EventTS>(
eventName: Key,
callback: (data: EventTS[Key]) => any,
listenOnce = false,
) => {
) {
const func = (event: MessageEvent<any>) => {
// --- Check for pluginMessage existence ---
if (event.data && event.data.pluginMessage) {
@ -43,9 +43,9 @@ export const listenTS = <Key extends keyof EventTS>(
}
};
window.addEventListener("message", func);
};
}
export const getColorTheme = () => {
export function getColorTheme(): "light" | "dark" {
if (window?.matchMedia) {
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
return "dark";
@ -55,11 +55,11 @@ export const getColorTheme = () => {
}
}
return "light";
};
}
export const subscribeColorTheme = (
export function subscribeColorTheme(
callback: (mode: "light" | "dark") => void,
) => {
) {
if (window?.matchMedia) {
window
.matchMedia("(prefers-color-scheme: dark)")
@ -71,4 +71,4 @@ export const subscribeColorTheme = (
}
});
}
};
}

View file

@ -38,9 +38,9 @@ export function writeTextToClipboard(str: string): boolean {
return copySuccessful;
}
export const downloadZipFile = async (
export async function downloadZipFile(
files: Array<{ name: string; content: string }>,
) => {
) {
try {
if (!files || files.length === 0) {
console.error("No files to zip!");
@ -79,9 +79,9 @@ export const downloadZipFile = async (
}, index * 100);
});
}
};
}
const downloadFile = (filename: string, text: string) => {
function downloadFile(filename: string, text: string) {
const element = document.createElement("a");
element.setAttribute(
"href",
@ -92,4 +92,4 @@ const downloadFile = (filename: string, text: string) => {
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
};
}