refactor(analytics): method per event instead of track(name, props)
analytics.showViewed({...}) reads better than track('show_viewed', {...}) and
drops the track_ alias Captions needed, where vidstack already exports track.
The methods are derived from the event catalogue with a mapped type plus a
Proxy rather than written out, so the catalogue stays the only place an event
is declared and the two cannot drift. Names stay snake_case on the wire.
Emitters are cached so a method is referentially stable and safe to pass to a
hook or use as an effect dependency.
Events with no payload are typed void and take no arguments.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d67a0d4df6
commit
01753d4eb6
16 files changed
+84
-40
No files matched your search
@@ -16,8 +16,8 @@ export type AnalyticsEvents = {
|
||||
gallery_tab_changed: { tab: string };
|
||||
|
||||
library_toggled: ShowRef & { list: 'favorite' | 'watchlist'; value: boolean };
|
||||
auth_completed: EmptyPayload;
|
||||
auth_signed_out: EmptyPayload;
|
||||
auth_completed: void;
|
||||
auth_signed_out: void;
|
||||
|
||||
torrents_searched: ShowRef & { provider: string; results: number };
|
||||
torrent_selected: { provider: string; seeders: number; quality?: string; source?: string; codec?: string };
|
||||
@@ -26,6 +26,4 @@ export type AnalyticsEvents = {
|
||||
subtitles_selected: { language: string };
|
||||
};
|
||||
|
||||
export type EmptyPayload = Record<string, never>;
|
||||
|
||||
export type AnalyticsEvent = keyof AnalyticsEvents;
|
||||
Reference in new issue
Block a user