Files
bitvid/js/bootstrap.js
google-labs-jules[bot]andPR0M3TH3AN 0665a3392e refactor(app): Move heavy initialization from constructor to setup()
- Introduces a `setup()` method in `Application` class to handle complex initialization and side effects.
- Updates `constructor` to be lightweight, only storing configuration options.
- Updates `js/bootstrap.js`, `js/embed.js`, and relevant tests to call `app.setup()` explicitly after instantiation.
- Resolves "Heavy Constructor" code health issue.
- Fixes `tests/video-modal-zap.test.mjs` environment issue with `globalThis.navigator`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-08 03:44:38 +00:00

42 lines
1.3 KiB
JavaScript

// js/bootstrap.js
import Application from "./app.js";
import nostrService from "./services/nostrService.js";
import r2Service from "./services/r2Service.js";
import s3UploadService from "./services/s3UploadService.js";
import { loadView } from "./viewManager.js";
import hashtagPreferences from "./services/hashtagPreferencesService.js";
import { userLogger } from "./utils/logger.js";
function mergeServices(overrides = {}) {
const merged = { nostrService, r2Service, s3Service: s3UploadService, hashtagPreferences };
if (overrides && typeof overrides === "object") {
if (overrides.nostrService) {
merged.nostrService = overrides.nostrService;
}
if (overrides.r2Service) {
merged.r2Service = overrides.r2Service;
}
if (overrides.s3Service) {
merged.s3Service = overrides.s3Service;
}
if (overrides.hashtagPreferences) {
merged.hashtagPreferences = overrides.hashtagPreferences;
}
}
return merged;
}
export async function createApplication({ services, loadView: loadViewOverride } = {}) {
const app = new Application({
services: mergeServices(services),
loadView: typeof loadViewOverride === "function" ? loadViewOverride : loadView,
});
app.setup();
return app;
}
export default createApplication;