Skip to content

Commit

Permalink
Fix client app init by switching to racer.createModel() since racer.M…
Browse files Browse the repository at this point in the history
…odel is now an abstract base class; change typings of app.model and page.model to be more specific RootModel instead of general Model
  • Loading branch information
ericyhwang committed Apr 11, 2024
1 parent 604e38a commit f3284b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, ComponentConstructor | SingletonComponentConstructor>;
protected _waitForAttach: boolean;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/AppForServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Derby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type Model,
type RootModel,
util,
ChangeEvent,
MoveEvent,
Expand Down Expand Up @@ -50,6 +51,7 @@ declare module 'racer' {
}

export abstract class Page extends Controller {
model: RootModel;
params: Readonly<PageParams>;
context: Context;
create: (model: Model, dom: any) => void;
Expand Down

0 comments on commit f3284b0

Please sign in to comment.