UNPKG

derby

Version:

MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.

86 lines (85 loc) 3.47 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { type Model, type RootModel } from 'racer'; import { util } from 'racer'; import { type ComponentConstructor, type SingletonComponentConstructor } from './components'; import { type Derby } from './Derby'; import { PageForClient, type Page } from './Page'; import { PageParams } from './routes'; import { type Views } from './templates/templates'; declare module 'racer/lib/util' { let isProduction: boolean; } export declare function createAppPage(derby: any): typeof Page; export interface AppOptions { appMetadata?: Record<string, string>; /** * Base URL that the JS bundles are served from, with no trailing slash. * Used by bundler plugins such as derby-webpack and derby-browserify. */ scriptBaseUrl?: string; /** * If true, then Derby's <script> tags have the `crossorigin` attribute set by the bundler plugin. */ scriptCrossOrigin?: boolean; /** * If set, this is used for auto-refresh in development to determine whether the browser * should auto-refresh due to running different code than the server. Some bundler plugins, * such as derby-webpack, do their own hot reload and don't use this mechanism. */ scriptHash?: string; /** * Base URL for js.map files, if different from scriptBaseUrl. */ scriptMapBaseUrl?: string; [key: string]: unknown; } type OnRouteCallback = (this: Page, page: Page, model: Model, params: PageParams, done?: () => void) => void; type Routes = [string, string, any][]; export declare abstract class App extends EventEmitter { derby: Derby; name: string; filename: string; scriptHash: string; appMetadata: Record<string, string>; Page: typeof Page; proto: any; views: Views; tracksRoutes: Routes; model: RootModel; page: Page; protected _pendingComponentMap: Record<string, ComponentConstructor | SingletonComponentConstructor>; protected _waitForAttach: boolean; protected _cancelAttach: boolean; use: typeof util.use; serverUse: typeof util.serverUse; constructor(derby: any, name?: string, filename?: string, options?: AppOptions); abstract _init(options?: AppOptions): any; loadViews(_viewFilename: any, _viewName?: any): void; loadStyles(_filename: any, _options?: any): void; component(constructor: ComponentConstructor | SingletonComponentConstructor): this; component(name: string, constructor: ComponentConstructor | SingletonComponentConstructor, isDependency?: boolean): this; addViews(_viewFileName: string, _namespace: string): void; onRoute(callback: OnRouteCallback, page: Page, next: () => void, done: () => void): void; } export declare class AppForClient extends App { page: PageForClient; history: { push: (url: string, render?: boolean, state?: object, e?: any) => void; replace: (url: string, render?: boolean, state?: object, e?: any) => void; refresh: () => void; }; constructor(derby: any, name: any, filename: any, options: AppOptions); _init(_options: any): void; private _views; private _finishInit; private _getAppData; private _contentReady; private _getAppStateScript; createPage(): PageForClient; private _destroyCurrentPage; private _autoRefresh; private _handleMessage; static _parseInitialData(jsonString: string): any; } export {};