From cb70d431d3bf74390588c61d88d0bb045fd7cd13 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 1 Nov 2024 14:45:30 +0100 Subject: [PATCH] fully type ui/api --- ui/@types/lichess/index.d.ts | 15 +++++++++++---- ui/site/src/api.ts | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/@types/lichess/index.d.ts b/ui/@types/lichess/index.d.ts index 367c7defeb63..c1ab01fb6040 100644 --- a/ui/@types/lichess/index.d.ts +++ b/ui/@types/lichess/index.d.ts @@ -161,14 +161,21 @@ interface Fipr { x64hash128(input: string, seed: number): string; } +interface Events { + on(key: string, cb: (...args: any[]) => void): void; + off(key: string, cb: (...args: any[]) => void): void; +} + interface Api { initializeDom: (root?: HTMLElement) => void; + events: Events; + socket: { + subscribeToMoveLatency: () => void; + events: Events; + }; onlineFriends: { request: () => void; - events: { - on(key: string, cb: (...args: any[]) => void): void; - off(key: string, cb: (...args: any[]) => void): void; - }; + events: Events; }; chat: { post: (text: string) => void; diff --git a/ui/site/src/api.ts b/ui/site/src/api.ts index d519d6b1741a..39328fe20e3e 100644 --- a/ui/site/src/api.ts +++ b/ui/site/src/api.ts @@ -6,7 +6,7 @@ const socketEvents = ['lag', 'close']; const socketInEvents = ['mlat', 'fen', 'notifications', 'endData']; const friendsEvents = ['playing', 'stopped_playing', 'onlines', 'enters', 'leaves']; -export const api = (pubsub: Pubsub) => ({ +export const api = (pubsub: Pubsub): Api => ({ initializeDom: (root?: HTMLElement) => pubsub.emit('content-loaded', root), events: { on(name: PubsubEvent, cb: PubsubCallback): void {