mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Move cohesive method groups out of the monolithic Application class (js/app.js, ~10K lines) into five coordinator modules under js/app/: - feedCoordinator: feed registration, runtime building, refresh, video loading, URL-health helpers, and feed telemetry - playbackCoordinator: URL-first + magnet fallback pipeline, probing, torrent status intervals, and video timestamp resolution - authSessionCoordinator: signer lifecycle, profile switching, relay/block/wallet management, and cleanup - modalCoordinator: modal open/close, view-count subscriptions, watch-history metadata, and playback logging - moderationCoordinator: moderation settings, video decoration, override/block/hide action routing Each coordinator factory receives injected dependencies instead of importing globals. Application retains thin delegator methods so all public call-sites remain unchanged. Coordinator initialisation is idempotent (via _initCoordinators) and supports both constructor-based and Object.create()-based instantiation used by test harnesses. All existing unit tests, lint checks, and syntax validation pass. https://claude.ai/code/session_01C3PKJTCdavsGbk5jjC85EB
23 lines
885 B
JavaScript
23 lines
885 B
JavaScript
// js/app/bindCoordinator.js
|
|
|
|
/**
|
|
* Binds every method on a coordinator object to the given Application instance.
|
|
*
|
|
* Coordinator factories return plain objects whose methods reference `this`
|
|
* (the Application) and close over injected `deps`. This helper produces a
|
|
* mirror object where every function-valued property is bound to `app`, so
|
|
* callers can invoke `coordinator.method()` without worrying about context.
|
|
*
|
|
* @param {object} app - The Application instance to bind to.
|
|
* @param {object} raw - The object returned by a coordinator factory.
|
|
* @returns {object} A new object with every method bound to `app`.
|
|
*/
|
|
export default function bindCoordinator(app, raw) {
|
|
const bound = Object.create(null);
|
|
for (const key of Object.keys(raw)) {
|
|
const value = raw[key];
|
|
bound[key] = typeof value === "function" ? value.bind(app) : value;
|
|
}
|
|
return bound;
|
|
}
|