Refactoring: simplifing the peertube context.
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user