UNPKG

@osaedasia/oresume

Version:

A user-friendly library for generating complete Single Page Applications (SPAs)

61 lines (60 loc) 2.73 kB
import { IPage } from "./interfaces/IPage"; import { QueryParamTypeMap } from "../../domain/definitions/types/QueryParam"; import { InternalPageDefinition } from "./types/PageDefinition"; /** * Manages page registration, validation, and lookup functionality in the application. * @template T The type for URL routing. * @template TParamTypeMap The type mapping for query parameters. */ export declare class PageManager<T extends string, TParamTypeMap extends QueryParamTypeMap = never> { /** * Collection of registered pages in the application. */ private readonly _pages; /** * Flag indicating whether URL-based routing is enabled. */ private readonly _urlBasedRouting; /** * Creates a new PageManager instance. * @param {boolean} urlBasedRouting Determines if URL-based routing should be used. */ constructor(urlBasedRouting: boolean); /** * Registers multiple pages in the application. * @param {InternalPageDefinition<T, TParamTypeMap>[]} pages Array of page definitions to register. * @throws {AppInitializedError} When attempting to register a page with a duplicate normalized URL. */ registerPages(pages: InternalPageDefinition<T, TParamTypeMap>[]): void; /** * Finds a page by its original URL. * @param {T} original The original URL to search for. * @returns {IPage<T, TParamTypeMap>} The matching page instance. * @throws {PageNotFoundError} When no page is found for the given URL. */ findPageByOriginalUrl(original: T): IPage<T, TParamTypeMap>; /** * Finds a page by its normalized URL. * @param {T | string} normalized The normalized URL to search for. * @returns {IPage<T, TParamTypeMap>} The matching page instance. * @throws {PageNotFoundError} When no page is found for the given normalized URL. */ findPageByNormalizedUrl(normalized: T | string): IPage<T, TParamTypeMap>; /** * Initializes a page instance with its definition, including callbacks and event listeners. * @param {InternalPageDefinition<T, TParamTypeMap>} definition The page definition to initialize. * @param {Page<T, TParamTypeMap>} pageInstance The page instance to initialize. */ private _initializePage; /** * Validates and adds a page to the collection. * @param {IPage<T, TParamTypeMap>} page The page to validate and add. * @throws {AppInitializedError} When a page with the same normalized URL already exists. */ private _validateAndAddPage; /** * Validates that at least one page exists in the application. * @throws {AppInitializedError} When no pages are registered. */ private _validatePagesExist; }