Refactoring: simplifing the peertube context.

This commit is contained in:
John Livingston
2024-06-12 16:26:35 +02:00
parent 268c60d699
commit 2c3739f633
13 changed files with 73 additions and 157 deletions

View File

@ -3,11 +3,22 @@
// SPDX-License-Identifier: AGPL-3.0-only
import type { RegisterClientOptions } from '@peertube/peertube-types/client/types'
import { createContext } from '@lit/context'
import { BehaviorSubject } from 'rxjs'
export const registerClientOptionsContext =
createContext<RegisterClientOptions | undefined>(Symbol('register-client-options'))
export interface PtContext {
ptOptions: RegisterClientOptions
}
export const registerClientOptionsSubject$ =
new BehaviorSubject<RegisterClientOptions | undefined>(undefined)
let context: PtContext
export function getPtContext (): PtContext {
if (!context) {
throw new Error('Peertube context not set yet, getPtContext was called too soon.')
}
return context
}
export function initPtContext (ptOptions: RegisterClientOptions): void {
context = {
ptOptions
}
}