Skip to content

Commit

Permalink
more type cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krisselden authored and rwjblue committed Oct 27, 2017
1 parent 5ee8966 commit 8c68f5b
Show file tree
Hide file tree
Showing 50 changed files with 628 additions and 459 deletions.
2 changes: 0 additions & 2 deletions broccoli/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const path = require('path');
const Rollup = require('broccoli-rollup');
const Funnel = require('broccoli-funnel');
const filterTypeScript = require('broccoli-typescript-compiler').filterTypeScript;
const TypeScriptPlugin = require('broccoli-typescript-compiler').TypeScriptPlugin;
const BroccoliDebug = require('broccoli-debug');
const MergeTrees = require('broccoli-merge-trees');
const findLib = require('./find-lib');
const funnelLib = require('./funnel-lib');
const { VERSION } = require('./version');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"resolve": "^1.3.3",
"rsvp": "^4.7.0",
"simple-dom": "^0.3.0",
"simple-html-tokenizer": "^0.4.1"
"simple-html-tokenizer": "^0.4.1",
"tslint": "^5.8.0"
},
"devDependencies": {
"aws-sdk": "^2.46.0",
Expand Down
19 changes: 0 additions & 19 deletions packages/container/tsconfig.json

This file was deleted.

73 changes: 48 additions & 25 deletions packages/ember-glimmer/lib/component-managers/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { ProgramSymbolTable } from '@glimmer/interfaces';
import { Tag, VersionedPathReference } from '@glimmer/reference';
import {
Bounds,
CompiledDynamicProgram,
CompiledDynamicTemplate,
ComponentDefinition,
ComponentManager,
DynamicScope,
ElementOperations,
Environment,
PreparedArguments,
} from '@glimmer/runtime';
import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments';
import { Destroyable, Opaque, Option } from '@glimmer/util';
import { DEBUG } from 'ember-env-flags';
import { Destroyable } from '@glimmer/util';

// implements the ComponentManager interface as defined in glimmer:
// tslint:disable-next-line:max-line-length
// https://github.com/glimmerjs/glimmer-vm/blob/v0.24.0-beta.4/packages/%40glimmer/runtime/lib/component/interfaces.ts#L21

export default class AbstractManager {
export default abstract class AbstractManager<T> implements ComponentManager<T> {
public debugStack: any;
public _pushToDebugStack: (name: string, environment: any) => void;
public _pushEngineToDebugStack: (name: string, environment: any) => void;
Expand All @@ -13,53 +28,61 @@ export default class AbstractManager {
this.debugStack = undefined;
}

prepareArgs(definition, args): any | null {
prepareArgs(definition: ComponentDefinition<T>, args: IArguments): Option<PreparedArguments> {
return null;
}

// must be implemented by inheritors, inheritors should also
// call `this._pushToDebugStack` to ensure the rerendering
// assertion messages are properly maintained
create(env, definition, args, dynamicScope, caller, hasBlock) {
if (DEBUG) {
throw new Error('AbstractManager#create must be implemented.');
}
}

layoutFor(definition, bucket, env) {
if (DEBUG) {
throw new Error('AbstractManager#create must be implemented.');
}
abstract create(
env: Environment,
definition: ComponentDefinition<T>,
args: IArguments,
dynamicScope: DynamicScope,
caller: VersionedPathReference<void | {}>,
hasDefaultBlock: boolean): T;
abstract layoutFor(
definition: ComponentDefinition<T>, component: T, env: Environment): CompiledDynamicTemplate<ProgramSymbolTable>;
abstract getSelf(component: T): VersionedPathReference<void | {}>;

didCreateElement(component: T, element: Element, operations: ElementOperations): void {
// noop
}

getSelf(bucket) { return bucket; }

didCreateElement(bucket, element, operations) { }

// inheritors should also call `this.debugStack.pop()` to
// ensure the rerendering assertion messages are properly
// maintained
didRenderLayout(bucket, bounds) { }
didRenderLayout(component: T, bounds: Bounds): void {
// noop
}

didCreate(bucket) { }
didCreate(bucket: T): void {
// noop
}

getTag(bucket) { return null; }
getTag(bucket: T): Option<Tag> { return null; }

// inheritors should also call `this._pushToDebugStack`
// to ensure the rerendering assertion messages are
// properly maintained
update(bucket, dynamicScope?) { }
update(bucket: T, dynamicScope: DynamicScope): void {
// noop
}

// inheritors should also call `this.debugStack.pop()` to
// ensure the rerendering assertion messages are properly
// maintained
didUpdateLayout(bucket, bounds) { }

didUpdate(bucket) { }
didUpdateLayout(bucket: T, bounds: Bounds): void {
// noop
}

getDestructor(bucket): Destroyable {
return bucket.component
didUpdate(bucket: T): void {
// noop
}

abstract getDestructor(bucket: T): Option<Destroyable>;
}

if (DEBUG) {
Expand Down
66 changes: 33 additions & 33 deletions packages/ember-glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import {
Opaque,
OWNER,
assign
} from 'ember-utils';
import { combineTagged } from '@glimmer/reference';
import {
ComponentDefinition,
PrimitiveReference,
ComponentDefinition
} from '@glimmer/runtime';
import { privatize as P } from 'container';
import {
assert
assert,
} from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
import {
ROOT_REF,
_instrumentStart,
get,
} from 'ember-metal';
import {
assign,
Opaque,
OWNER,
} from 'ember-utils';
import { setViewElement } from 'ember-views';
import {
BOUNDS,
DIRTY_TAG,
IS_DISPATCHING_ATTRS,
HAS_BLOCK,
BOUNDS
IS_DISPATCHING_ATTRS,
ROOT_REF,
} from '../component';
import {
AttributeBinding,
ClassNameBinding,
IsVisibleBinding
IsVisibleBinding,
} from '../utils/bindings';
import {
get,
_instrumentStart
} from 'ember-metal';
import { processComponentArgs } from '../utils/process-args';
import { setViewElement } from 'ember-views';
import { privatize as P } from 'container';
import AbstractManager from './abstract';
import ComponentStateBucket from '../utils/curly-component-state-bucket';
import { processComponentArgs } from '../utils/process-args';
import { PropertyReference } from '../utils/references';
import AbstractManager from './abstract';

const DEFAULT_LAYOUT = P`template:components/-default`;

Expand All @@ -48,12 +48,12 @@ function aliasIdToElementId(args, props) {
// what has already been applied. This is essentially refining the concatenated
// properties applying right to left.
function applyAttributeBindings(element, attributeBindings, component, operations) {
let seen: Array<string> = [];
let seen: string[] = [];
let i = attributeBindings.length - 1;

while (i !== -1) {
let binding = attributeBindings[i];
let parsed: Array<string> = AttributeBinding.parse(binding);
let parsed: string[] = AttributeBinding.parse(binding);
let attribute = parsed[1];

if (seen.indexOf(attribute) === -1) {
Expand Down Expand Up @@ -111,15 +111,15 @@ export class PositionalArgumentReference {
}

value() {
return this._references.map(reference => reference.value());
return this._references.map((reference) => reference.value());
}

get(key) {
return PropertyReference.create(this, key);
}
}

export default class CurlyComponentManager extends AbstractManager {
export default class CurlyComponentManager extends AbstractManager<ComponentStateBucket> {
prepareArgs(definition, args) {
let componentPositionalParamsDefinition = definition.ComponentClass.class.positionalParams;

Expand Down Expand Up @@ -152,10 +152,10 @@ export default class CurlyComponentManager extends AbstractManager {
let positionalParamsToNamed;
if (componentHasRestStylePositionalParams) {
positionalParamsToNamed = {
[componentPositionalParamsDefinition]: new PositionalArgumentReference(positional)
[componentPositionalParamsDefinition]: new PositionalArgumentReference(positional),
};
positional = [];
} else if (componentHasPositionalParams){
} else if (componentHasPositionalParams) {
positionalParamsToNamed = {};
let length = Math.min(positional.length, componentPositionalParamsDefinition.length);
for (let i = 0; i < length; i++) {
Expand All @@ -171,7 +171,7 @@ export default class CurlyComponentManager extends AbstractManager {

create(environment, definition, args, dynamicScope, callerSelfRef, hasBlock) {
if (DEBUG) {
this._pushToDebugStack(`component:${definition.name}`, environment)
this._pushToDebugStack(`component:${definition.name}`, environment);
}

let parentView = dynamicScope.view;
Expand Down Expand Up @@ -274,13 +274,13 @@ export default class CurlyComponentManager extends AbstractManager {
}

if (classNames && classNames.length) {
classNames.forEach(name => {
classNames.forEach((name) => {
operations.addStaticAttribute(element, 'class', name);
});
}

if (classNameBindings && classNameBindings.length) {
classNameBindings.forEach(binding => {
classNameBindings.forEach((binding) => {
ClassNameBinding.install(element, component, binding, operations);
});
}
Expand Down Expand Up @@ -313,11 +313,11 @@ export default class CurlyComponentManager extends AbstractManager {
}
}

update(bucket) {
update(bucket: ComponentStateBucket) {
let { component, args, argsRevision, environment } = bucket;

if (DEBUG) {
this._pushToDebugStack(component._debugContainerKey, environment)
this._pushToDebugStack(component._debugContainerKey, environment);
}

bucket.finalizer = _instrumentStart('render.component', rerenderInstrumentDetails, component);
Expand All @@ -341,7 +341,7 @@ export default class CurlyComponentManager extends AbstractManager {
}
}

didUpdateLayout(bucket) {
didUpdateLayout(bucket: ComponentStateBucket) {
bucket.finalize();

if (DEBUG) {
Expand All @@ -356,7 +356,7 @@ export default class CurlyComponentManager extends AbstractManager {
}
}

getDestructor(stateBucket) {
getDestructor(stateBucket: ComponentStateBucket) {
return stateBucket;
}
}
Expand All @@ -381,7 +381,7 @@ export function validatePositionalParameters(named, positional, positionalParams

assert(
`You cannot specify both a positional param (at position ${i}) and the hash argument \`${name}\`.`,
!named.has(name)
!named.has(name),
);
}
}
Expand Down
37 changes: 16 additions & 21 deletions packages/ember-glimmer/lib/component-managers/mount.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
import {
ComponentDefinition
ComponentDefinition,
} from '@glimmer/runtime';
import {
Opaque
Opaque,
} from '@glimmer/util';
import { DEBUG } from 'ember-env-flags';

import { RootReference } from '../utils/references';
import { OutletLayoutCompiler } from './outlet';
import AbstractManager from './abstract';
import { generateControllerFactory } from 'ember-routing';
import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features';
import { RootReference } from '../utils/references';
import AbstractManager from './abstract';
import { OutletLayoutCompiler } from './outlet';

//TODO: remove these stubbed interfaces when better typing is in place
interface engineType {
// TODO: remove these stubbed interfaces when better typing is in place
interface EngineType {
boot(): void;
};
}

interface bucketType {
interface EngineBucket {
modelReference?: any;
engine: engineType;
};


class MountManager extends AbstractManager {
prepareArgs(definition, args) {
return null;
}
engine: EngineType;
}

class MountManager extends AbstractManager<EngineBucket> {
create(environment, { name }, args, dynamicScope) {
if (DEBUG) {
this._pushEngineToDebugStack(`engine:${name}`, environment)
this._pushEngineToDebugStack(`engine:${name}`, environment);
}

let engine: engineType = environment.owner.buildChildEngineInstance(name);
let engine: EngineType = environment.owner.buildChildEngineInstance(name);

engine.boot();

let bucket: bucketType = { engine };
let bucket: EngineBucket = { engine };

if (EMBER_ENGINES_MOUNT_PARAMS) {
bucket.modelReference = args.named.get('model');
Expand Down Expand Up @@ -73,7 +68,7 @@ class MountManager extends AbstractManager {

didRenderLayout() {
if (DEBUG) {
this.debugStack.pop()
this.debugStack.pop();
}
}

Expand Down
Loading

0 comments on commit 8c68f5b

Please sign in to comment.