yeow-api 0.2.34 → 0.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/event.ts +8 -8
package/package.json
CHANGED
package/src/event.ts
CHANGED
|
@@ -322,26 +322,26 @@ export function eventOn<K extends keyof EventMap>(
|
|
|
322
322
|
$send('task', { type: 'event.complete', params: { callbackId: cbId, mods }, cb: '' });
|
|
323
323
|
}, { persistent: true });
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!
|
|
328
|
-
|
|
325
|
+
const gh = globalThis as any;
|
|
326
|
+
if (!gh.__yeowEventHandlers) gh.__yeowEventHandlers = {};
|
|
327
|
+
if (!gh.__yeowEventHandlers[eventType]) gh.__yeowEventHandlers[eventType] = [];
|
|
328
|
+
gh.__yeowEventHandlers[eventType].push({ cbId, handler, manualRelease });
|
|
329
329
|
|
|
330
330
|
call('event.subscribe', { pluginName, eventType, callbackId: String(cbId) });
|
|
331
331
|
return () => eventOff(eventType, handler);
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
export function eventOff(eventType: string, handler: Function): void {
|
|
335
|
-
|
|
336
|
-
const entries = __yeowEventHandlers[eventType];
|
|
335
|
+
const gh = globalThis as any;
|
|
336
|
+
const entries = gh.__yeowEventHandlers?.[eventType];
|
|
337
337
|
if (!entries) return;
|
|
338
|
-
const idx = entries.findIndex((e) => e.handler === handler);
|
|
338
|
+
const idx = entries.findIndex((e: any) => e.handler === handler);
|
|
339
339
|
if (idx !== -1) {
|
|
340
340
|
const removed = entries.splice(idx, 1)[0];
|
|
341
341
|
if (removed.cbId) _unregisterCallback(removed.cbId);
|
|
342
342
|
}
|
|
343
343
|
if (entries.length === 0) {
|
|
344
|
-
delete __yeowEventHandlers
|
|
344
|
+
delete gh.__yeowEventHandlers[eventType];
|
|
345
345
|
call('event.unsubscribe', {
|
|
346
346
|
pluginName: __plugin?.name || 'unknown',
|
|
347
347
|
eventType,
|