Skip to content

Commit c24bdb7

Browse files
format with prettier
1 parent eb2d311 commit c24bdb7

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

packages/api/src/mocks.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
// SPDX-License-Identifier: MIT
44

55
import type { InvokeArgs, InvokeOptions } from './core'
6-
import { EventName } from './event';
6+
import { EventName } from './event'
77

88
function mockInternals() {
99
window.__TAURI_INTERNALS__ = window.__TAURI_INTERNALS__ ?? {}
10-
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = window.__TAURI_EVENT_PLUGIN_INTERNALS__ ?? {}
10+
window.__TAURI_EVENT_PLUGIN_INTERNALS__ =
11+
window.__TAURI_EVENT_PLUGIN_INTERNALS__ ?? {}
1112
}
1213

1314
/**
@@ -92,58 +93,55 @@ export function mockIPC(
9293
): void {
9394
mockInternals()
9495

95-
9696
function isEventPluginInvoke(cmd: string): boolean {
97-
return cmd.startsWith('plugin:event|');
97+
return cmd.startsWith('plugin:event|')
9898
}
9999

100100
function handleEventPlugin(cmd: string, args?: InvokeArgs): unknown {
101101
switch (cmd.split('|')[1]) {
102102
case 'listen':
103-
return handleListen(args as {event: EventName, handler: number});
103+
return handleListen(args as { event: EventName; handler: number })
104104
case 'emit':
105-
return handleEmit(args as {event: EventName, payload?: unknown});
105+
return handleEmit(args as { event: EventName; payload?: unknown })
106106
case 'unlisten':
107-
return handleRemoveListener(args as {event: EventName, id: number});
107+
return handleRemoveListener(args as { event: EventName; id: number })
108108
}
109109
}
110110

111-
const listeners = new Map<string, number[]>();
112-
function handleListen(args: { event: EventName, handler: number }) {
111+
const listeners = new Map<string, number[]>()
112+
function handleListen(args: { event: EventName; handler: number }) {
113113
if (!listeners.has(args.event)) {
114-
listeners.set(args.event, []);
114+
listeners.set(args.event, [])
115115
}
116-
listeners.get(args.event)!.push(args.handler);
117-
return args.handler;
116+
listeners.get(args.event)!.push(args.handler)
117+
return args.handler
118118
}
119119

120-
function handleEmit(args: { event: EventName, payload?: unknown }) {
121-
const eventListeners = listeners.get(args.event) || [];
120+
function handleEmit(args: { event: EventName; payload?: unknown }) {
121+
const eventListeners = listeners.get(args.event) || []
122122
for (const handler of eventListeners) {
123-
runCallback(handler, args);
123+
runCallback(handler, args)
124124
}
125-
return null;
125+
return null
126126
}
127-
function handleRemoveListener(args: { event: EventName, id: number }) {
128-
const eventListeners = listeners.get(args.event);
127+
function handleRemoveListener(args: { event: EventName; id: number }) {
128+
const eventListeners = listeners.get(args.event)
129129
if (eventListeners) {
130-
const index = eventListeners.indexOf(args.id);
130+
const index = eventListeners.indexOf(args.id)
131131
if (index !== -1) {
132-
eventListeners.splice(index, 1);
132+
eventListeners.splice(index, 1)
133133
}
134134
}
135135
}
136136

137-
138137
// eslint-disable-next-line @typescript-eslint/require-await
139138
async function invoke<T>(
140139
cmd: string,
141140
args?: InvokeArgs,
142141
_options?: InvokeOptions
143142
): Promise<T> {
144-
145143
if (isEventPluginInvoke(cmd)) {
146-
return handleEventPlugin(cmd, args) as T;
144+
return handleEventPlugin(cmd, args) as T
147145
}
148146

149147
return cb(cmd, args) as T
@@ -182,15 +180,16 @@ export function mockIPC(
182180
}
183181

184182
function unregisterListener(event: EventName, id: number) {
185-
unregisterCallback(id);
183+
unregisterCallback(id)
186184
}
187185

188186
window.__TAURI_INTERNALS__.invoke = invoke
189187
window.__TAURI_INTERNALS__.transformCallback = registerCallback
190188
window.__TAURI_INTERNALS__.unregisterCallback = unregisterCallback
191189
window.__TAURI_INTERNALS__.runCallback = runCallback
192190
window.__TAURI_INTERNALS__.callbacks = callbacks
193-
window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener = unregisterListener
191+
window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener =
192+
unregisterListener
194193
}
195194

196195
/**

0 commit comments

Comments
 (0)