| 8 | import { ActionDescriptorFilter, ActionDescriptorFilters, defaultActionDescriptorFilters } from "./action_descriptor" |
| 9 | |
| 10 | export class Application implements ErrorHandler { |
| 11 | readonly element: Element |
| 12 | readonly schema: Schema |
| 13 | readonly dispatcher: Dispatcher |
| 14 | readonly router: Router |
| 15 | readonly actionDescriptorFilters: ActionDescriptorFilters |
| 16 | logger: Logger = console |
| 17 | debug = false |
| 18 | |
| 19 | static start(element?: Element, schema?: Schema): Application { |
| 20 | const application = new this(element, schema) |
| 21 | application.start() |
| 22 | return application |
| 23 | } |
| 24 | |
| 25 | constructor(element: Element = document.documentElement, schema: Schema = defaultSchema) { |
| 26 | this.element = element |
| 27 | this.schema = schema |
| 28 | this.dispatcher = new Dispatcher(this) |
| 29 | this.router = new Router(this) |
| 30 | this.actionDescriptorFilters = { ...defaultActionDescriptorFilters } |
| 31 | } |
| 32 | |
| 33 | async start() { |
| 34 | await domReady() |
| 35 | this.logDebugActivity("application", "starting") |
| 36 | this.dispatcher.start() |
| 37 | this.router.start() |
| 38 | this.logDebugActivity("application", "start") |
| 39 | } |
| 40 | |
| 41 | stop() { |
| 42 | this.logDebugActivity("application", "stopping") |
| 43 | this.dispatcher.stop() |
| 44 | this.router.stop() |
| 45 | this.logDebugActivity("application", "stop") |
| 46 | } |
| 47 | |
| 48 | register(identifier: string, controllerConstructor: ControllerConstructor) { |
| 49 | this.load({ identifier, controllerConstructor }) |
| 50 | } |
| 51 | |
| 52 | registerActionOption(name: string, filter: ActionDescriptorFilter) { |
| 53 | this.actionDescriptorFilters[name] = filter |
| 54 | } |
| 55 | |
| 56 | load(...definitions: Definition[]): void |
| 57 | load(definitions: Definition[]): void |
| 58 | load(head: Definition | Definition[], ...rest: Definition[]) { |
| 59 | const definitions = Array.isArray(head) ? head : [head, ...rest] |
| 60 | definitions.forEach((definition) => { |
| 61 | if ((definition.controllerConstructor as any).shouldLoad) { |
| 62 | this.router.loadDefinition(definition) |
| 63 | } |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | unload(...identifiers: string[]): void |
nothing calls this directly
no test coverage detected
searching dependent graphs…