diff --git a/src/App.ts b/src/App.ts index 22c41a4a..06c0103b 100644 --- a/src/App.ts +++ b/src/App.ts @@ -8,7 +8,7 @@ import { EventEmitter } from 'events'; import { basename } from 'path'; -import { type Model } from 'racer'; +import { type Model, type RootModel, createModel } from 'racer'; import { util } from 'racer'; import * as components from './components'; @@ -71,7 +71,7 @@ export abstract class AppBase extends EventEmitter { proto: any; views: Views; tracksRoutes: Routes; - model: Model; + model: RootModel; page: Page; protected _pendingComponentMap: Record; protected _waitForAttach: boolean; @@ -99,7 +99,7 @@ export abstract class AppBase extends EventEmitter { abstract _init(options?: AppOptions); loadViews(_viewFilename, _viewName?) { } - loadStyles(_filename, _options) { } + loadStyles(_filename, _options?) { } component(constructor: ComponentConstructor | SingletonComponentConstructor): this; component(name: string, constructor: ComponentConstructor | SingletonComponentConstructor, isDependency?: boolean): this; @@ -259,7 +259,7 @@ export class App extends AppBase { _init(_options) { this._waitForAttach = true; this._cancelAttach = false; - this.model = new this.derby.Model(); + this.model = createModel(); const serializedViews = this._views(); serializedViews(derbyTemplates, this.views); // Must init async so that app.on('model') listeners can be added. diff --git a/src/AppForServer.ts b/src/AppForServer.ts index b56e81ab..7b8e6fe3 100644 --- a/src/AppForServer.ts +++ b/src/AppForServer.ts @@ -147,7 +147,7 @@ export class AppForServer extends AppBase { // overload w different signatures, but different use cases createPage(req, res, next) { - const model = req.model || new racer.Model(); + const model = req.model || racer.createModel(); this.emit('model', model); const Page = this.Page as unknown as typeof PageForServer; diff --git a/src/Derby.ts b/src/Derby.ts index 71dd606d..dda783ef 100644 --- a/src/Derby.ts +++ b/src/Derby.ts @@ -3,7 +3,7 @@ * Meant to be the entry point for the framework. * */ -import { Racer, util, type Model} from 'racer'; +import { Racer, util } from 'racer'; import { App, type AppBase, type AppOptions } from './App'; import { Component } from './components'; @@ -13,14 +13,12 @@ export abstract class DerbyBase extends Racer { Component = Component; // App: typeof AppBase; // Page: typeof PageBase; - Model: typeof Model; abstract createApp(name?: string, filename?: string, options?: AppOptions): AppBase } export class Derby extends DerbyBase { App = App; Page = PageForClient; - Model: typeof Model; createApp(name?: string, filename?: string, options?: AppOptions) { return new this.App(this, name, filename, options); diff --git a/src/Page.ts b/src/Page.ts index 2ed363ca..c0cc33e2 100644 --- a/src/Page.ts +++ b/src/Page.ts @@ -1,5 +1,6 @@ import { type Model, + type RootModel, util, ChangeEvent, MoveEvent, @@ -50,6 +51,7 @@ declare module 'racer' { } export abstract class Page extends Controller { + model: RootModel; params: Readonly; context: Context; create: (model: Model, dom: any) => void;