Skip to content

Commit

Permalink
Merge branch 'ts-conversion-1' of github.com:derbyjs/derby into ts-co…
Browse files Browse the repository at this point in the history
…nversion-1
  • Loading branch information
craigbeck committed Oct 6, 2023
2 parents 67d60fb + 211bb7b commit 2150df6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ export abstract class PageBase extends Controller {

destroy() {
this.emit('destroy');
if (this._removeModelListeners) {
this._removeModelListeners();
}
this._removeModelListeners();
for (const id in this._components) {
const component = this._components[id];
component.destroy();
Expand Down
13 changes: 10 additions & 3 deletions src/parsing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import htmlUtil = require('html-util');

import { createPathExpression } from './createPathExpression';
import { markup } from './markup';
import { App } from '../App';
import { App, AppBase } from '../App';
import { templates, expressions } from '../templates';
import { Expression } from '../templates/expressions';
import { MarkupHook, View } from '../templates/templates';
Expand All @@ -18,6 +18,13 @@ declare module '../App' {
}
}

interface ParsedView {
name: string;
source: string;
options: unknown;
filename?: string;
}

// View.prototype._parse is defined here, so that it doesn't have to
// be included in the client if templates are all parsed server-side
templates.View.prototype._parse = function() {
Expand Down Expand Up @@ -881,7 +888,7 @@ export function getImportNamespace(namespace: string, attrs: Record<string, stri
}

export function parseViews(file: string, namespace: string, filename?: string, onImport?: (attrs) => void) {
const views = [];
const views: ParsedView[] = [];
const prefix = (namespace) ? namespace + ':' : '';

htmlUtil.parse(file + '\n', {
Expand Down Expand Up @@ -933,7 +940,7 @@ export function parseViews(file: string, namespace: string, filename?: string, o
return views;
}

export function registerParsedViews(app, items) {
export function registerParsedViews(app: AppBase, items: ParsedView[]) {
for (let i = 0, len = items.length; i < len; i++) {
const item = items[i];
app.views.register(item.name, item.source, item.options);
Expand Down
15 changes: 3 additions & 12 deletions src/templates/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ import * as operatorFns from './operatorFns';
import { ContextClosure, Dependency, Template } from './templates';
import { concat } from './util';
import { Component } from '../components';
import { Controller } from '../Controller';
import { Page } from '../Page';

type SegmentOrContext = string | number | { item: number } | Context;
type Segment = string | number;
type Value = any; // global | Page | ModelData

function isPage(controller: Controller): controller is Page {
return !Object.prototype.hasOwnProperty.call((controller as Page), '_scope');
}

export function lookup(segments: Segment[] | undefined, value: Value) {
if (!segments) return value;

Expand Down Expand Up @@ -685,12 +679,9 @@ export class FnExpression extends Expression {
if (fn) {
break;
}
if (isPage(controller)) {
controller = undefined;
break;
}
const component = controller as Component;
controller = component.parent;
// controller could be a Component or a PageBase in practice,
// using `as Component` to avoid a runtime instanceof check.
controller = (controller as Component).parent;
}
const setFn = fn && fn.set;
if (!setFn) throw new Error('No setter function for: ' + this.segments.join('.'));
Expand Down
4 changes: 2 additions & 2 deletions src/templates/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ export class DynamicViewInstance extends BaseViewInstance {
const contextView = context.getView();
const namespace = contextView && contextView.namespace;
const view = name && context.meta.views.find(name, namespace);
return view || exports.emptyTemplate;
return view || emptyTemplate;
}

dependencies(context: Context, options: { ignoreTemplate?: Template; }) {
Expand Down Expand Up @@ -2203,7 +2203,7 @@ export class Views {
// For views with the `server` option, serialize them with a blank
// template body. This allows them to be used from other views on the
// browser, but they will output nothing on the browser
if (view.options.server) template = exports.emptyTemplate;
if (view.options.server) template = emptyTemplate;
}
// Serializing views as a function allows them to be constructed lazily upon
// first use. This can improve initial load times of the application when
Expand Down

0 comments on commit 2150df6

Please sign in to comment.