From 8c68f5b26f50af456af214065d3b411006d420da Mon Sep 17 00:00:00 2001 From: Kris Selden Date: Wed, 25 Oct 2017 17:30:04 -0700 Subject: [PATCH] more type cleanup --- broccoli/packages.js | 2 - package.json | 3 +- packages/container/tsconfig.json | 19 --- .../lib/component-managers/abstract.ts | 73 +++++++---- .../lib/component-managers/curly.ts | 66 +++++----- .../lib/component-managers/mount.ts | 37 +++--- .../lib/component-managers/outlet.ts | 28 +++-- .../lib/component-managers/render.ts | 32 +++-- .../lib/component-managers/root.ts | 16 +-- packages/ember-glimmer/lib/component.ts | 49 ++++---- .../ember-glimmer/lib/components/checkbox.ts | 4 +- .../ember-glimmer/lib/components/link-to.ts | 33 +++-- .../ember-glimmer/lib/components/text_area.ts | 8 +- .../lib/components/text_field.ts | 10 +- packages/ember-glimmer/lib/environment.ts | 101 ++++++++-------- packages/ember-glimmer/lib/helper.ts | 12 +- packages/ember-glimmer/lib/helpers/-class.ts | 2 +- .../lib/helpers/-normalize-class.ts | 2 +- packages/ember-glimmer/lib/helpers/action.ts | 16 +-- .../ember-glimmer/lib/helpers/component.ts | 16 +-- packages/ember-glimmer/lib/helpers/concat.ts | 2 +- packages/ember-glimmer/lib/helpers/get.ts | 13 +- .../ember-glimmer/lib/helpers/if-unless.ts | 18 +-- packages/ember-glimmer/lib/helpers/loc.ts | 2 +- packages/ember-glimmer/lib/helpers/mut.ts | 2 +- .../ember-glimmer/lib/helpers/query-param.ts | 6 +- .../ember-glimmer/lib/helpers/readonly.ts | 1 - packages/ember-glimmer/lib/helpers/unbound.ts | 2 +- packages/ember-glimmer/lib/index.ts | 6 +- .../ember-glimmer/lib/modifiers/action.ts | 16 +-- packages/ember-glimmer/lib/renderer.ts | 113 +++++++++++------- packages/ember-glimmer/lib/setup-registry.ts | 28 ++--- packages/ember-glimmer/lib/syntax.ts | 16 +-- .../lib/syntax/dynamic-component.ts | 2 +- packages/ember-glimmer/lib/syntax/input.ts | 2 +- packages/ember-glimmer/lib/syntax/mount.ts | 12 +- packages/ember-glimmer/lib/syntax/outlet.ts | 4 +- packages/ember-glimmer/lib/syntax/render.ts | 5 +- packages/ember-glimmer/lib/syntax/utils.ts | 4 +- packages/ember-glimmer/lib/template.ts | 50 ++++++-- .../ember-glimmer/lib/template_registry.ts | 2 +- packages/ember-glimmer/lib/utils/bindings.ts | 14 +-- .../lib/utils/curly-component-state-bucket.ts | 9 +- packages/ember-glimmer/lib/utils/iterable.ts | 32 ++--- .../ember-glimmer/lib/utils/process-args.ts | 4 +- .../ember-glimmer/lib/utils/references.ts | 51 ++++---- packages/ember-glimmer/lib/utils/string.ts | 6 +- packages/ember-glimmer/lib/utils/to-bool.ts | 2 +- packages/ember-glimmer/lib/views/outlet.ts | 60 ++++++---- yarn.lock | 74 +++++++++++- 50 files changed, 628 insertions(+), 459 deletions(-) delete mode 100644 packages/container/tsconfig.json diff --git a/broccoli/packages.js b/broccoli/packages.js index 5d560f7a334..2e5f2c46cc8 100644 --- a/broccoli/packages.js +++ b/broccoli/packages.js @@ -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'); diff --git a/package.json b/package.json index 433ebc6a0a1..2c9026fff89 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/container/tsconfig.json b/packages/container/tsconfig.json deleted file mode 100644 index 67cf7ff1ab1..00000000000 --- a/packages/container/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2015", - "module": "es2015", - "moduleResolution": "node", - "baseUrl": ".", - "paths": { - "*": ["packages/*/lib/index"] - } - }, - "include": [ - "container/**/*.ts" - ], - "exclude": [ - "node_modules", - "packages", - "**/*.d.ts" - ] -} diff --git a/packages/ember-glimmer/lib/component-managers/abstract.ts b/packages/ember-glimmer/lib/component-managers/abstract.ts index e374fceea0f..52578116d1f 100644 --- a/packages/ember-glimmer/lib/component-managers/abstract.ts +++ b/packages/ember-glimmer/lib/component-managers/abstract.ts @@ -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 implements ComponentManager { public debugStack: any; public _pushToDebugStack: (name: string, environment: any) => void; public _pushEngineToDebugStack: (name: string, environment: any) => void; @@ -13,53 +28,61 @@ export default class AbstractManager { this.debugStack = undefined; } - prepareArgs(definition, args): any | null { + prepareArgs(definition: ComponentDefinition, args: IArguments): Option { 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, + args: IArguments, + dynamicScope: DynamicScope, + caller: VersionedPathReference, + hasDefaultBlock: boolean): T; + abstract layoutFor( + definition: ComponentDefinition, component: T, env: Environment): CompiledDynamicTemplate; + abstract getSelf(component: T): VersionedPathReference; + + 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 { 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; } if (DEBUG) { diff --git a/packages/ember-glimmer/lib/component-managers/curly.ts b/packages/ember-glimmer/lib/component-managers/curly.ts index 8d6573a1054..901883a5a58 100644 --- a/packages/ember-glimmer/lib/component-managers/curly.ts +++ b/packages/ember-glimmer/lib/component-managers/curly.ts @@ -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`; @@ -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 = []; + let seen: string[] = []; let i = attributeBindings.length - 1; while (i !== -1) { let binding = attributeBindings[i]; - let parsed: Array = AttributeBinding.parse(binding); + let parsed: string[] = AttributeBinding.parse(binding); let attribute = parsed[1]; if (seen.indexOf(attribute) === -1) { @@ -111,7 +111,7 @@ export class PositionalArgumentReference { } value() { - return this._references.map(reference => reference.value()); + return this._references.map((reference) => reference.value()); } get(key) { @@ -119,7 +119,7 @@ export class PositionalArgumentReference { } } -export default class CurlyComponentManager extends AbstractManager { +export default class CurlyComponentManager extends AbstractManager { prepareArgs(definition, args) { let componentPositionalParamsDefinition = definition.ComponentClass.class.positionalParams; @@ -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++) { @@ -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; @@ -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); }); } @@ -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); @@ -341,7 +341,7 @@ export default class CurlyComponentManager extends AbstractManager { } } - didUpdateLayout(bucket) { + didUpdateLayout(bucket: ComponentStateBucket) { bucket.finalize(); if (DEBUG) { @@ -356,7 +356,7 @@ export default class CurlyComponentManager extends AbstractManager { } } - getDestructor(stateBucket) { + getDestructor(stateBucket: ComponentStateBucket) { return stateBucket; } } @@ -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), ); } } diff --git a/packages/ember-glimmer/lib/component-managers/mount.ts b/packages/ember-glimmer/lib/component-managers/mount.ts index 9b1fd4ff4a6..6b6f52c35a6 100644 --- a/packages/ember-glimmer/lib/component-managers/mount.ts +++ b/packages/ember-glimmer/lib/component-managers/mount.ts @@ -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 { 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'); @@ -73,7 +68,7 @@ class MountManager extends AbstractManager { didRenderLayout() { if (DEBUG) { - this.debugStack.pop() + this.debugStack.pop(); } } diff --git a/packages/ember-glimmer/lib/component-managers/outlet.ts b/packages/ember-glimmer/lib/component-managers/outlet.ts index cf5da00f177..688b6be51b2 100644 --- a/packages/ember-glimmer/lib/component-managers/outlet.ts +++ b/packages/ember-glimmer/lib/component-managers/outlet.ts @@ -1,9 +1,13 @@ -import { generateGuid, guidFor } from 'ember-utils'; +import { Option } from '@glimmer/interfaces/dist/types'; import { - ComponentDefinition + ComponentDefinition, + DynamicScope, } from '@glimmer/runtime'; +import { Destroyable } from '@glimmer/util/dist/types'; import { DEBUG } from 'ember-env-flags'; +import { Environment } from 'ember-glimmer'; import { _instrumentStart } from 'ember-metal'; +import { generateGuid, guidFor } from 'ember-utils'; import { RootReference } from '../utils/references'; import AbstractManager from './abstract'; @@ -11,7 +15,11 @@ function instrumentationPayload({ render: { name, outlet } }) { return { object: `${name}:${outlet}` }; } -function NOOP() {} +function NOOP() {/**/} + +interface OutletDynamicScope extends DynamicScope { + outletState: any; +} class StateBucket { public outletState: any; @@ -33,13 +41,14 @@ class StateBucket { } } -class OutletComponentManager extends AbstractManager { - create(environment, definition, args, dynamicScope) { +class OutletComponentManager extends AbstractManager { + create(environment: Environment, definition: OutletComponentDefinition, args, dynamicScope: OutletDynamicScope) { if (DEBUG) { this._pushToDebugStack(`template:${definition.template.meta.moduleName}`, environment); } - let outletStateReference = dynamicScope.outletState = dynamicScope.outletState.get('outlets').get(definition.outletName); + let outletStateReference = dynamicScope.outletState = + dynamicScope.outletState.get('outlets').get(definition.outletName); let outletState = outletStateReference.value(); return new StateBucket(outletState); } @@ -59,6 +68,10 @@ class OutletComponentManager extends AbstractManager { this.debugStack.pop(); } } + + getDestructor(bucket: StateBucket): Option { + return null; + } } const MANAGER = new OutletComponentManager(); @@ -78,8 +91,7 @@ class TopLevelOutletComponentManager extends OutletComponentManager { const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager(); - -export class TopLevelOutletComponentDefinition extends ComponentDefinition { +export class TopLevelOutletComponentDefinition extends ComponentDefinition { public template: any; constructor(instance) { super('outlet', TOP_LEVEL_MANAGER, instance); diff --git a/packages/ember-glimmer/lib/component-managers/render.ts b/packages/ember-glimmer/lib/component-managers/render.ts index f89a06fbd79..7d18834b193 100644 --- a/packages/ember-glimmer/lib/component-managers/render.ts +++ b/packages/ember-glimmer/lib/component-managers/render.ts @@ -1,14 +1,22 @@ import { - ComponentDefinition + VersionedPathReference, +} from '@glimmer/reference'; +import { + ComponentDefinition, } from '@glimmer/runtime'; +import { IArguments } from '@glimmer/runtime/dist/types/lib/vm/arguments'; +import { Destroyable } from '@glimmer/util'; + import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; -import { RootReference } from '../utils/references'; import { generateController, generateControllerFactory } from 'ember-routing'; -import { OutletLayoutCompiler } from './outlet'; +import Environment from '../environment'; +import { DynamicScope } from '../renderer'; +import { RootReference } from '../utils/references'; import AbstractManager from './abstract'; +import { OutletLayoutCompiler } from './outlet'; -export class AbstractRenderManager extends AbstractManager { +export abstract class AbstractRenderManager extends AbstractManager { layoutFor(definition, bucket, env) { return env.getCompiledBlock(OutletLayoutCompiler, definition.template); } @@ -24,13 +32,17 @@ if (DEBUG) { }; } +export interface RenderState { + controller: Destroyable; +} + class SingletonRenderManager extends AbstractRenderManager { - create(environment, definition, args, dynamicScope) { - let { name, env } = definition; + create(env: Environment, definition: ComponentDefinition, args: IArguments, dynamicScope: DynamicScope) { + let { name } = definition; let controller = env.owner.lookup(`controller:${name}`) || generateController(env.owner, name); if (DEBUG) { - this._pushToDebugStack(`controller:${name} (with the render helper)`, environment); + this._pushToDebugStack(`controller:${name} (with the render helper)`, env); } if (dynamicScope.rootOutletState) { @@ -39,6 +51,10 @@ class SingletonRenderManager extends AbstractRenderManager { return { controller }; } + + getDestructor() { + return null; + } } export const SINGLETON_RENDER_MANAGER = new SingletonRenderManager(); @@ -77,7 +93,7 @@ export const NON_SINGLETON_RENDER_MANAGER = new NonSingletonRenderManager(); export class RenderDefinition extends ComponentDefinition { public name: string; public template: any; - public env: any; + public env: Environment; constructor(name, template, env, manager) { super('render', manager, null); diff --git a/packages/ember-glimmer/lib/component-managers/root.ts b/packages/ember-glimmer/lib/component-managers/root.ts index 0ecba2a3314..24d6f484c0b 100644 --- a/packages/ember-glimmer/lib/component-managers/root.ts +++ b/packages/ember-glimmer/lib/component-managers/root.ts @@ -1,17 +1,17 @@ import { - ComponentDefinition + ComponentDefinition, } from '@glimmer/runtime'; import { - _instrumentStart -} from 'ember-metal'; -import { - assert + assert, } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; +import { + _instrumentStart, +} from 'ember-metal'; import ComponentStateBucket from '../utils/curly-component-state-bucket'; import CurlyComponentManager, { initialRenderInstrumentDetails, - processComponentInitializationAssertions + processComponentInitializationAssertions, } from './curly'; class RootComponentManager extends CurlyComponentManager { @@ -19,7 +19,7 @@ class RootComponentManager extends CurlyComponentManager { let component = definition.ComponentClass.create(); if (DEBUG) { - this._pushToDebugStack(component._debugContainerKey, environment) + this._pushToDebugStack(component._debugContainerKey, environment); } let finalizer = _instrumentStart('render.component', initialRenderInstrumentDetails, component); @@ -57,7 +57,7 @@ export class RootComponentDefinition extends ComponentDefinition { class: instance.constructor, create() { return instance; - } + }, }); this.template = undefined; this.args = undefined; diff --git a/packages/ember-glimmer/lib/component.ts b/packages/ember-glimmer/lib/component.ts index 87be2b1ed7d..5a803347758 100644 --- a/packages/ember-glimmer/lib/component.ts +++ b/packages/ember-glimmer/lib/component.ts @@ -1,25 +1,25 @@ -import { symbol, getOwner, NAME_KEY } from 'ember-utils'; -import { - CoreView, - ClassNamesSupport, - ChildViewsSupport, - ViewStateSupport, - ViewMixin, - ActionSupport, - getViewElement -} from 'ember-views'; -import { TargetActionSupport } from 'ember-runtime'; +import { DirtyableTag } from '@glimmer/reference'; +import { readDOMAttr } from '@glimmer/runtime'; import { assert, - deprecate + deprecate, } from 'ember-debug'; import { get, PROPERTY_DID_CHANGE, } from 'ember-metal'; -import { UPDATE, RootReference } from './utils/references'; -import { DirtyableTag } from '@glimmer/reference'; -import { readDOMAttr } from '@glimmer/runtime'; +import { TargetActionSupport } from 'ember-runtime'; +import { getOwner, NAME_KEY, symbol } from 'ember-utils'; +import { + ActionSupport, + ChildViewsSupport, + ClassNamesSupport, + CoreView, + getViewElement, + ViewMixin, + ViewStateSupport, +} from 'ember-views'; +import { RootReference, UPDATE } from './utils/references'; export const DIRTY_TAG = symbol('DIRTY_TAG'); export const ARGS = symbol('ARGS'); @@ -109,7 +109,6 @@ export const BOUNDS = symbol('BOUNDS'); elements. This is consistent with the same requirement in web components. - ## HTML Tag The default HTML tag name used for a component's DOM representation is `div`. @@ -130,7 +129,6 @@ export const BOUNDS = symbol('BOUNDS'); ``` - ## HTML `class` Attribute The HTML `class` attribute of a component's tag can be set by providing a @@ -315,7 +313,6 @@ export const BOUNDS = symbol('BOUNDS'); [EmberObject](/api/classes/Ember.Object.html) documentation for more information about concatenated properties. - ## HTML Attributes The HTML attribute section of a component's tag can be set by providing an @@ -438,7 +435,6 @@ export const BOUNDS = symbol('BOUNDS'); `attributeBindings` is a concatenated property. See [EmberObject](/api/classes/Ember.Object.html) documentation for more information about concatenated properties. - ## Layouts See [Ember.Templates.helpers.yield](/api/classes/Ember.Templates.helpers.html#method_yield) @@ -472,14 +468,12 @@ export const BOUNDS = symbol('BOUNDS'); ``` - ## Responding to Browser Events Components can respond to user-initiated events in one of three ways: method implementation, through an event manager, and through `{{action}}` helper use in their template or layout. - ### Method Implementation Components can respond to user-initiated events by implementing a method that @@ -497,12 +491,10 @@ export const BOUNDS = symbol('BOUNDS'); }); ``` - ### `{{action}}` Helper See [Ember.Templates.helpers.action](/api/classes/Ember.Templates.helpers.html#method_action). - ### Event Names All of the event handling approaches described above respond to the same set @@ -589,8 +581,8 @@ const Component = CoreView.extend( { id: 'ember-views.component.defaultLayout', until: '3.0.0', - url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-component-defaultlayout' - } + url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-component-defaultlayout', + }, ); this.layout = this.defaultLayout; @@ -676,7 +668,7 @@ const Component = CoreView.extend( readDOMAttr(name) { let element = getViewElement(this); return readDOMAttr(element, name); - } + }, /** The WAI-ARIA role of the control represented by this view. For example, a @@ -754,7 +746,6 @@ const Component = CoreView.extend( @since 1.13.0 */ - /** Called when the attributes passed into the component have been updated. Called both during the initial render of a container and during a rerender. @@ -921,14 +912,14 @@ const Component = CoreView.extend( @default null @public */ - } + }, ); Component[NAME_KEY] = 'Ember.Component'; Component.reopenClass({ isComponentFactory: true, - positionalParams: [] + positionalParams: [], }); export default Component; diff --git a/packages/ember-glimmer/lib/components/checkbox.ts b/packages/ember-glimmer/lib/components/checkbox.ts index 0cc8bb66e69..e8c82835fb4 100644 --- a/packages/ember-glimmer/lib/components/checkbox.ts +++ b/packages/ember-glimmer/lib/components/checkbox.ts @@ -44,7 +44,7 @@ export default EmberComponent.extend({ 'name', 'autofocus', 'required', - 'form' + 'form', ], type: 'checkbox', @@ -58,5 +58,5 @@ export default EmberComponent.extend({ change() { set(this, 'checked', this.$().prop('checked')); - } + }, }); diff --git a/packages/ember-glimmer/lib/components/link-to.ts b/packages/ember-glimmer/lib/components/link-to.ts index 03ec18a30ef..f2c5254ae8a 100644 --- a/packages/ember-glimmer/lib/components/link-to.ts +++ b/packages/ember-glimmer/lib/components/link-to.ts @@ -313,23 +313,25 @@ import Logger from 'ember-console'; import { assert, deprecate } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; import { - get, computed, - flaggedInstrument + flaggedInstrument, + get, } from 'ember-metal'; import { + ControllerMixin, deprecatingAlias, inject, - ControllerMixin } from 'ember-runtime'; import { isSimpleClick } from 'ember-views'; -import layout from '../templates/link-to'; import EmberComponent, { HAS_BLOCK } from '../component'; -import { DEBUG } from 'ember-env-flags'; +import layout from '../templates/link-to'; + /** @module @ember/routing */ + /** `LinkComponent` renders an element whose `click` event triggers a transition of the application's instance of `Router` to @@ -433,7 +435,6 @@ const LinkComponent = EmberComponent.extend({ @private **/ disabledClass: 'disabled', - _isDisabled: false, /** Determines whether the `LinkComponent` will trigger routing via @@ -524,6 +525,7 @@ const LinkComponent = EmberComponent.extend({ */ init() { this._super(...arguments); + this._isDisabled = false; // Map desired event name to invoke function let eventName = get(this, 'eventName'); @@ -548,7 +550,7 @@ const LinkComponent = EmberComponent.extend({ if (value !== undefined) { this.set('_isDisabled', value); } return value ? get(this, 'disabledClass') : false; - } + }, }), _isActive(routerState) { @@ -651,6 +653,7 @@ const LinkComponent = EmberComponent.extend({ if (get(this, '_isDisabled')) { return false; } if (get(this, 'loading')) { + // tslint:disable-next-line:max-line-length Logger.warn('This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.'); return false; } @@ -666,9 +669,10 @@ const LinkComponent = EmberComponent.extend({ let payload = { queryParams, - routeName: qualifiedRouteName + routeName: qualifiedRouteName, }; + // tslint:disable-next-line:max-line-length flaggedInstrument('interaction.link-to', payload, this._generateTransition(payload, qualifiedRouteName, models, queryParams, shouldReplace)); }, @@ -681,7 +685,8 @@ const LinkComponent = EmberComponent.extend({ queryParams: null, - qualifiedRouteName: computed('targetRouteName', '_routing.currentState', function computeLinkToComponentQualifiedRouteName() { + qualifiedRouteName: computed('targetRouteName', '_routing.currentState', + function computeLinkToComponentQualifiedRouteName() { let params = get(this, 'params'); let paramsLength = params.length; let lastParam = params[paramsLength - 1]; @@ -746,6 +751,7 @@ const LinkComponent = EmberComponent.extend({ try { routing.generateURL(qualifiedRouteName, models, queryParams); } catch (e) { + // tslint:disable-next-line:max-line-length assert('You attempted to define a `{{link-to "' + qualifiedRouteName + '"}}` but did not pass the parameters required for generating its dynamic segments. ' + e.message); } } @@ -781,9 +787,10 @@ const LinkComponent = EmberComponent.extend({ while (ControllerMixin.detect(value)) { deprecate( 'Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated. ' + - (this.parentView ? 'Please update `' + this.parentView + '` to use `{{link-to "post" someController.model}}` instead.' : ''), + (this.parentView ? 'Please update `' + this.parentView + + '` to use `{{link-to "post" someController.model}}` instead.' : ''), false, - { id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' } + { id: 'ember-routing-views.controller-wrapped-param', until: '3.0.0' }, ); value = value.get('model'); } @@ -847,13 +854,13 @@ const LinkComponent = EmberComponent.extend({ } else { this.set('models', []); } - } + }, }); LinkComponent.toString = () => 'LinkComponent'; LinkComponent.reopenClass({ - positionalParams: 'params' + positionalParams: 'params', }); export default LinkComponent; diff --git a/packages/ember-glimmer/lib/components/text_area.ts b/packages/ember-glimmer/lib/components/text_area.ts index e4cc0359caa..b6888239c2a 100644 --- a/packages/ember-glimmer/lib/components/text_area.ts +++ b/packages/ember-glimmer/lib/components/text_area.ts @@ -1,8 +1,8 @@ /** @module @ember/component */ -import Component from '../component'; import { TextSupport } from 'ember-views'; +import Component from '../component'; import layout from '../templates/empty'; /** @@ -217,7 +217,7 @@ import layout from '../templates/empty'; export default Component.extend(TextSupport, { classNames: ['ember-text-area'], - layout: layout, + layout, tagName: 'textarea', attributeBindings: [ @@ -229,8 +229,8 @@ export default Component.extend(TextSupport, { 'wrap', 'lang', 'dir', - 'value' + 'value', ], rows: null, - cols: null + cols: null, }); diff --git a/packages/ember-glimmer/lib/components/text_field.ts b/packages/ember-glimmer/lib/components/text_field.ts index 51528c94ab8..ef4fa752d4b 100644 --- a/packages/ember-glimmer/lib/components/text_field.ts +++ b/packages/ember-glimmer/lib/components/text_field.ts @@ -1,11 +1,11 @@ /** @module @ember/component */ -import { computed } from 'ember-metal'; import { environment } from 'ember-environment'; +import { computed } from 'ember-metal'; +import { TextSupport } from 'ember-views'; import Component from '../component'; import layout from '../templates/empty'; -import { TextSupport } from 'ember-views'; const inputTypes = Object.create(null); function canSetTypeOfInput(type) { @@ -76,7 +76,7 @@ export default Component.extend(TextSupport, { 'size', 'step', 'value', - 'width' + 'width', ], /** @@ -111,7 +111,7 @@ export default Component.extend(TextSupport, { } return type; - } + }, }), /** @@ -154,5 +154,5 @@ export default Component.extend(TextSupport, { @since 1.4.0 @public */ - max: null + max: null, }); diff --git a/packages/ember-glimmer/lib/environment.ts b/packages/ember-glimmer/lib/environment.ts index 1c5cf392466..cfebd674cbd 100644 --- a/packages/ember-glimmer/lib/environment.ts +++ b/packages/ember-glimmer/lib/environment.ts @@ -1,72 +1,73 @@ /// -import { guidFor, OWNER } from 'ember-utils'; -import { Cache, _instrumentStart } from 'ember-metal'; -import { assert, warn } from 'ember-debug'; -import { DEBUG } from 'ember-env-flags'; -import { - lookupPartial, - hasPartial, - lookupComponent, - constructStyleDeprecationMessage -} from 'ember-views'; import { - Reference + Reference, } from '@glimmer/reference'; import { - Environment as GlimmerEnvironment, AttributeManager, - isSafeString, compileLayout, - getDynamicVar, DOMTreeConstruction, - PartialDefinition + Environment as GlimmerEnvironment, + getDynamicVar, + isSafeString, + PartialDefinition, } from '@glimmer/runtime'; import { - Opaque + Destroyable, Opaque, } from '@glimmer/util'; +import { assert, warn } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; +import { _instrumentStart, Cache } from 'ember-metal'; +import { guidFor, OWNER } from 'ember-utils'; import { - CurlyComponentDefinition + constructStyleDeprecationMessage, + hasPartial, + lookupComponent, + lookupPartial, +} from 'ember-views'; +import { + CurlyComponentDefinition, } from './component-managers/curly'; import { - populateMacros + populateMacros, } from './syntax'; +import DebugStack from './utils/debug-stack'; import createIterable from './utils/iterable'; import { + ClassBasedHelperReference, ConditionalReference, SimpleHelperReference, - ClassBasedHelperReference } from './utils/references'; -import DebugStack from './utils/debug-stack'; -import { - inlineIf, - inlineUnless -} from './helpers/if-unless'; +import { default as classHelper } from './helpers/-class'; +import { default as htmlSafeHelper } from './helpers/-html-safe'; +import { default as inputTypeHelper } from './helpers/-input-type'; +import { default as normalizeClassHelper } from './helpers/-normalize-class'; import { default as action } from './helpers/action'; import { default as componentHelper } from './helpers/component'; import { default as concat } from './helpers/concat'; +import { default as eachIn } from './helpers/each-in'; import { default as get } from './helpers/get'; import { default as hash } from './helpers/hash'; +import { + inlineIf, + inlineUnless, +} from './helpers/if-unless'; import { default as loc } from './helpers/loc'; import { default as log } from './helpers/log'; import { default as mut } from './helpers/mut'; +import { default as queryParams } from './helpers/query-param'; import { default as readonly } from './helpers/readonly'; import { default as unbound } from './helpers/unbound'; -import { default as classHelper } from './helpers/-class'; -import { default as inputTypeHelper } from './helpers/-input-type'; -import { default as queryParams } from './helpers/query-param'; -import { default as eachIn } from './helpers/each-in'; -import { default as normalizeClassHelper } from './helpers/-normalize-class'; -import { default as htmlSafeHelper } from './helpers/-html-safe'; -import installPlatformSpecificProtocolForURL from './protocol-for-url'; import { default as ActionModifierManager } from './modifiers/action'; +import installPlatformSpecificProtocolForURL from './protocol-for-url'; +import { DOMChanges } from '@glimmer/runtime/dist/types/lib/dom/helper'; import { + EMBER_MODULE_UNIFICATION, GLIMMER_CUSTOM_COMPONENT_MANAGER, - EMBER_MODULE_UNIFICATION } from 'ember/features'; -import { DOMChanges } from "@glimmer/runtime/dist/types/lib/dom/helper"; +import { Container } from './template'; function instrumentationPayload(name) { return { object: `component:${name}` }; @@ -77,12 +78,16 @@ export default class Environment extends GlimmerEnvironment { return new this(options); } - public owner: any; + public owner: Container; public isInteractive: boolean; - public destroyedComponents: Array; - public builtInModifiers: any; - public builtInHelpers: any; - public debugStack: any; + public destroyedComponents: Destroyable[]; + public builtInModifiers: { + [name: string]: any; + }; + public builtInHelpers: { + [name: string]: any; + }; + public debugStack: typeof DebugStack; public inTransaction: boolean; private _definitionCache: Cache; private _templateCache: Cache; @@ -100,7 +105,7 @@ export default class Environment extends GlimmerEnvironment { this._definitionCache = new Cache(2000, ({ name, source, owner }) => { let { component: componentFactory, layout } = lookupComponent(owner, name, { source }); - let customManager = undefined; + let customManager; if (componentFactory || layout) { if (GLIMMER_CUSTOM_COMPONENT_MANAGER) { @@ -130,22 +135,22 @@ export default class Environment extends GlimmerEnvironment { } }, ({ Template, owner }) => guidFor(owner) + '|' + Template.id); - this._compilerCache = new Cache(10, Compiler => { + this._compilerCache = new Cache(10, (Compiler) => { return new Cache(2000, (template) => { let compilable = new Compiler(template); return compileLayout(compilable, this); - }, (template)=> { + }, (template) => { let owner = template.meta.owner; return guidFor(owner) + '|' + template.id; }); - }, Compiler => Compiler.id); + }, (Compiler) => Compiler.id); this.builtInModifiers = { - action: new ActionModifierManager() + action: new ActionModifierManager(), }; this.builtInHelpers = { - if: inlineIf, + 'if': inlineIf, action, concat, get, @@ -156,17 +161,17 @@ export default class Environment extends GlimmerEnvironment { 'query-params': queryParams, readonly, unbound, - unless: inlineUnless, + 'unless': inlineUnless, '-class': classHelper, '-each-in': eachIn, '-input-type': inputTypeHelper, '-normalize-class': normalizeClassHelper, '-html-safe': htmlSafeHelper, - '-get-dynamic-var': getDynamicVar + '-get-dynamic-var': getDynamicVar, }; if (DEBUG) { - this.debugStack = new DebugStack() + this.debugStack = new DebugStack(); } } @@ -219,7 +224,7 @@ export default class Environment extends GlimmerEnvironment { lookupPartial(name: string, meta: any): PartialDefinition { let partial = { name, - template: lookupPartial(name, meta.owner) + template: lookupPartial(name, meta.owner), }; if (partial.template) { diff --git a/packages/ember-glimmer/lib/helper.ts b/packages/ember-glimmer/lib/helper.ts index 1bc71d8be09..3ff1594ae31 100644 --- a/packages/ember-glimmer/lib/helper.ts +++ b/packages/ember-glimmer/lib/helper.ts @@ -2,9 +2,9 @@ @module @ember/component */ -import { symbol } from 'ember-utils'; -import { FrameworkObject } from 'ember-runtime'; import { DirtyableTag } from '@glimmer/reference'; +import { FrameworkObject } from 'ember-runtime'; +import { symbol } from 'ember-utils'; export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG'); @@ -50,7 +50,7 @@ export const RECOMPUTE_TAG = symbol('RECOMPUTE_TAG'); @public @since 1.13.0 */ -var Helper = FrameworkObject.extend({ +let Helper = FrameworkObject.extend({ isHelperInstance: true, init() { @@ -87,7 +87,7 @@ var Helper = FrameworkObject.extend({ */ recompute() { this[RECOMPUTE_TAG].dirty(); - } + }, /** Override this function when writing a class-based helper. @@ -101,7 +101,7 @@ var Helper = FrameworkObject.extend({ }); Helper.reopenClass({ - isHelperFactory: true + isHelperFactory: true, }); /** @@ -129,7 +129,7 @@ Helper.reopenClass({ export function helper(helperFn) { return { isHelperInstance: true, - compute: helperFn + compute: helperFn, }; } diff --git a/packages/ember-glimmer/lib/helpers/-class.ts b/packages/ember-glimmer/lib/helpers/-class.ts index 2d780793490..6dc8f5d3705 100644 --- a/packages/ember-glimmer/lib/helpers/-class.ts +++ b/packages/ember-glimmer/lib/helpers/-class.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; function classHelper({ positional }) { let path = positional.at(0); diff --git a/packages/ember-glimmer/lib/helpers/-normalize-class.ts b/packages/ember-glimmer/lib/helpers/-normalize-class.ts index 4d347ac658a..beaef34c08a 100644 --- a/packages/ember-glimmer/lib/helpers/-normalize-class.ts +++ b/packages/ember-glimmer/lib/helpers/-normalize-class.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; function normalizeClass({ positional, named }) { let classNameParts = positional.at(0).value().split('.'); diff --git a/packages/ember-glimmer/lib/helpers/action.ts b/packages/ember-glimmer/lib/helpers/action.ts index 12214373c1c..d9d54ee3e7e 100644 --- a/packages/ember-glimmer/lib/helpers/action.ts +++ b/packages/ember-glimmer/lib/helpers/action.ts @@ -1,17 +1,17 @@ /** @module ember */ -import { symbol } from 'ember-utils'; +import { isConst } from '@glimmer/reference'; +import { assert } from 'ember-debug'; +import { DEBUG } from 'ember-env-flags'; import { - run, - get, flaggedInstrument, - isNone + get, + isNone, + run, } from 'ember-metal'; +import { symbol } from 'ember-utils'; import { UnboundReference } from '../utils/references'; -import { isConst } from '@glimmer/reference'; -import { assert } from 'ember-debug'; -import { DEBUG } from 'ember-env-flags'; export const INVOKE = symbol('INVOKE'); export const ACTION = symbol('ACTION'); @@ -309,7 +309,7 @@ function makeArgsProcessor(valuePathRef, actionArgsRef) { if (actionArgsRef.length > 0) { mergeArgs = function(args) { - return actionArgsRef.map(ref => ref.value()).concat(args); + return actionArgsRef.map((ref) => ref.value()).concat(args); }; } diff --git a/packages/ember-glimmer/lib/helpers/component.ts b/packages/ember-glimmer/lib/helpers/component.ts index e161660efa1..40b2f18ea62 100644 --- a/packages/ember-glimmer/lib/helpers/component.ts +++ b/packages/ember-glimmer/lib/helpers/component.ts @@ -1,16 +1,16 @@ /** @module ember */ +import { + isComponentDefinition, +} from '@glimmer/runtime'; +import { assert } from 'ember-debug'; import { assign } from 'ember-utils'; -import { CachedReference } from '../utils/references'; import { CurlyComponentDefinition, - validatePositionalParameters + validatePositionalParameters, } from '../component-managers/curly'; -import { - isComponentDefinition -} from '@glimmer/runtime'; -import { assert } from 'ember-debug'; +import { CachedReference } from '../utils/references'; /** The `{{component}}` helper lets you add instances of `Component` to a @@ -193,7 +193,7 @@ export class ClosureComponentReference extends CachedReference { } else { assert( `You cannot create a component from ${nameOrDef} using the {{component}} helper`, - nameOrDef + nameOrDef, ); return null; } @@ -213,7 +213,7 @@ function createCurriedDefinition(definition, args) { definition.name, definition.ComponentClass, definition.template, - curriedArgs + curriedArgs, ); } diff --git a/packages/ember-glimmer/lib/helpers/concat.ts b/packages/ember-glimmer/lib/helpers/concat.ts index b4db9711e54..d9a289ef8cf 100644 --- a/packages/ember-glimmer/lib/helpers/concat.ts +++ b/packages/ember-glimmer/lib/helpers/concat.ts @@ -1,5 +1,5 @@ -import { InternalHelperReference } from '../utils/references'; import { normalizeTextValue } from '@glimmer/runtime'; +import { InternalHelperReference } from '../utils/references'; /** @module ember diff --git a/packages/ember-glimmer/lib/helpers/get.ts b/packages/ember-glimmer/lib/helpers/get.ts index 3a10eefccb7..e897e9998cb 100644 --- a/packages/ember-glimmer/lib/helpers/get.ts +++ b/packages/ember-glimmer/lib/helpers/get.ts @@ -1,17 +1,16 @@ -import { set } from 'ember-metal'; -import { CachedReference, UPDATE } from '../utils/references'; import { + combine, CONSTANT_TAG, + isConst, + referenceFromParts, TagWrapper, UpdatableTag, - combine, - isConst, - referenceFromParts } from '@glimmer/reference'; import { - NULL_REFERENCE + NULL_REFERENCE, } from '@glimmer/runtime'; - +import { set } from 'ember-metal'; +import { CachedReference, UPDATE } from '../utils/references'; /** @module ember diff --git a/packages/ember-glimmer/lib/helpers/if-unless.ts b/packages/ember-glimmer/lib/helpers/if-unless.ts index 84084280619..668d7db0c66 100644 --- a/packages/ember-glimmer/lib/helpers/if-unless.ts +++ b/packages/ember-glimmer/lib/helpers/if-unless.ts @@ -2,18 +2,18 @@ @module ember */ -import { assert } from 'ember-debug'; -import { - CachedReference, - ConditionalReference -} from '../utils/references'; import { + combine, CONSTANT_TAG, + isConst, TagWrapper, UpdatableTag, - combine, - isConst } from '@glimmer/reference'; +import { assert } from 'ember-debug'; +import { + CachedReference, + ConditionalReference, +} from '../utils/references'; class ConditionalHelperReference extends CachedReference { public branchTag: TagWrapper; @@ -137,7 +137,7 @@ export function inlineIf(vm, { positional }) { assert( 'The inline form of the `if` helper expects two or three arguments, e.g. ' + '`{{if trialExpired "Expired" expiryDate}}`.', - positional.length === 3 || positional.length === 2 + positional.length === 3 || positional.length === 2, ); return ConditionalHelperReference.create(positional.at(0), positional.at(1), positional.at(2)); } @@ -166,7 +166,7 @@ export function inlineUnless(vm, { positional }) { assert( 'The inline form of the `unless` helper expects two or three arguments, e.g. ' + '`{{unless isFirstLogin "Welcome back!"}}`.', - positional.length === 3 || positional.length === 2 + positional.length === 3 || positional.length === 2, ); return ConditionalHelperReference.create(positional.at(0), positional.at(2), positional.at(1)); } diff --git a/packages/ember-glimmer/lib/helpers/loc.ts b/packages/ember-glimmer/lib/helpers/loc.ts index 3e1a1d75064..b6d9d9ac66a 100644 --- a/packages/ember-glimmer/lib/helpers/loc.ts +++ b/packages/ember-glimmer/lib/helpers/loc.ts @@ -2,8 +2,8 @@ /** @module ember */ -import { InternalHelperReference } from '../utils/references'; import { String as StringUtils } from 'ember-runtime'; +import { InternalHelperReference } from '../utils/references'; /** Calls [loc](/api/classes/Ember.String.html#method_loc) with the diff --git a/packages/ember-glimmer/lib/helpers/mut.ts b/packages/ember-glimmer/lib/helpers/mut.ts index 945374b212b..d490a779cc3 100644 --- a/packages/ember-glimmer/lib/helpers/mut.ts +++ b/packages/ember-glimmer/lib/helpers/mut.ts @@ -1,8 +1,8 @@ /** @module ember */ -import { symbol } from 'ember-utils'; import { assert } from 'ember-debug'; +import { symbol } from 'ember-utils'; import { UPDATE } from '../utils/references'; import { INVOKE } from './action'; diff --git a/packages/ember-glimmer/lib/helpers/query-param.ts b/packages/ember-glimmer/lib/helpers/query-param.ts index 19f2971f65a..9c8af51f491 100644 --- a/packages/ember-glimmer/lib/helpers/query-param.ts +++ b/packages/ember-glimmer/lib/helpers/query-param.ts @@ -1,10 +1,10 @@ /** @module ember */ -import { assign } from 'ember-utils'; -import { InternalHelperReference } from '../utils/references'; import { assert } from 'ember-debug'; import { QueryParams } from 'ember-routing'; +import { assign } from 'ember-utils'; +import { InternalHelperReference } from '../utils/references'; /** This is a helper to be used in conjunction with the link-to helper. @@ -26,7 +26,7 @@ function queryParams({ positional, named }) { assert('The `query-params` helper only accepts hash parameters, e.g. (query-params queryParamPropertyName=\'foo\') as opposed to just (query-params \'foo\')', positional.value().length === 0); return QueryParams.create({ - values: assign({}, named.value()) + values: assign({}, named.value()), }); } diff --git a/packages/ember-glimmer/lib/helpers/readonly.ts b/packages/ember-glimmer/lib/helpers/readonly.ts index 9d5092bf126..031ecf194ea 100644 --- a/packages/ember-glimmer/lib/helpers/readonly.ts +++ b/packages/ember-glimmer/lib/helpers/readonly.ts @@ -4,7 +4,6 @@ import { UPDATE } from '../utils/references'; import { unMut } from './mut'; - /** The `readonly` helper let's you specify that a binding is one-way only, instead of two-way. diff --git a/packages/ember-glimmer/lib/helpers/unbound.ts b/packages/ember-glimmer/lib/helpers/unbound.ts index 3c2543e2068..30cb8f8fe06 100644 --- a/packages/ember-glimmer/lib/helpers/unbound.ts +++ b/packages/ember-glimmer/lib/helpers/unbound.ts @@ -36,7 +36,7 @@ import { UnboundReference } from '../utils/references'; export default function(vm, args) { assert( 'unbound helper cannot be called with multiple params or hash params', - args.positional.length === 1 && args.named.length === 0 + args.positional.length === 1 && args.named.length === 0, ); return UnboundReference.create(args.positional.at(0).value()); diff --git a/packages/ember-glimmer/lib/index.ts b/packages/ember-glimmer/lib/index.ts index 4622e8d06dd..e6484511aa7 100644 --- a/packages/ember-glimmer/lib/index.ts +++ b/packages/ember-glimmer/lib/index.ts @@ -274,20 +274,20 @@ export { escapeExpression, htmlSafe, isHTMLSafe, - getSafeString as _getSafeString + getSafeString as _getSafeString, } from './utils/string'; export { Renderer, InertRenderer, InteractiveRenderer, - _resetRenderers + _resetRenderers, } from './renderer'; export { getTemplate, setTemplate, hasTemplate, getTemplates, - setTemplates + setTemplates, } from './template_registry'; export { setupEngineRegistry, setupApplicationRegistry } from './setup-registry'; export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './dom'; diff --git a/packages/ember-glimmer/lib/modifiers/action.ts b/packages/ember-glimmer/lib/modifiers/action.ts index 3e590226cf1..c276607dfac 100644 --- a/packages/ember-glimmer/lib/modifiers/action.ts +++ b/packages/ember-glimmer/lib/modifiers/action.ts @@ -1,9 +1,9 @@ -import { uuid } from 'ember-utils'; -import { run, flaggedInstrument } from 'ember-metal'; import { assert } from 'ember-debug'; +import { flaggedInstrument, run } from 'ember-metal'; +import { uuid } from 'ember-utils'; import { + ActionManager, isSimpleClick, - ActionManager } from 'ember-views'; import { INVOKE } from '../helpers/action'; @@ -49,7 +49,7 @@ export let ActionHelper = { let { actionId } = actionState; delete ActionManager.registeredActions[actionId]; - } + }, }; export class ActionState { @@ -126,7 +126,7 @@ export class ActionState { let payload = { args, target, - name: null + name: null, }; if (typeof actionName[INVOKE] === 'function') { flaggedInstrument('interaction.ember-action', payload, () => { @@ -148,7 +148,7 @@ export class ActionState { } else { assert( `The action '${actionName}' did not exist on ${target}`, - typeof target[actionName] === 'function' + typeof target[actionName] === 'function', ); flaggedInstrument('interaction.ember-action', payload, () => { target[actionName].apply(target, args); @@ -184,7 +184,7 @@ export default class ActionModifierManager { '{{action}} helper which did not resolve to an action name (a ' + 'string). Perhaps you meant to use a quoted actionName? (e.g. ' + '{{action "' + actionLabel + '"}}).', - typeof actionName === 'string' || typeof actionName === 'function' + typeof actionName === 'string' || typeof actionName === 'function', ); } } @@ -205,7 +205,7 @@ export default class ActionModifierManager { named, positional, implicitTarget, - dom + dom, ); } diff --git a/packages/ember-glimmer/lib/renderer.ts b/packages/ember-glimmer/lib/renderer.ts index 54b180bebad..30b33ba1428 100644 --- a/packages/ember-glimmer/lib/renderer.ts +++ b/packages/ember-glimmer/lib/renderer.ts @@ -2,49 +2,55 @@ interface FreeformObject { [key: string]: any; } -import { RootReference } from './utils/references'; +import { Simple } from '@glimmer/interfaces'; +import { CURRENT_TAG, VersionedPathReference } from '@glimmer/reference'; +import { IteratorResult } from '@glimmer/runtime'; +import { Opaque } from '@glimmer/util'; +import { assert } from 'ember-debug'; +import { Environment } from 'ember-glimmer'; import { run, + runInTransaction, setHasViews, - runInTransaction } from 'ember-metal'; -import { CURRENT_TAG } from '@glimmer/reference'; import { fallbackViewRegistry, getViewElement, + getViewId, setViewElement, - getViewId } from 'ember-views'; import { BOUNDS } from './component'; -import { RootComponentDefinition } from './component-managers/root'; import { TopLevelOutletComponentDefinition } from './component-managers/outlet'; -import { assert } from 'ember-debug'; +import { RootComponentDefinition } from './component-managers/root'; +import { OwnedTemplate } from './template'; +import { RootReference } from './utils/references'; +import OutletView, { OutletState, OutletStateReference } from './views/outlet'; -const { backburner } = run; +import { ComponentDefinition, RenderResult } from '@glimmer/runtime'; -class DynamicScope { - private view: any - private outletState: any - private rootOutletState: any +const { backburner } = run; - constructor(view, outletState, rootOutletState) { - this.view = view; - this.outletState = outletState; - this.rootOutletState = rootOutletState; +export class DynamicScope { + constructor( + public view: Opaque, + public outletState?: VersionedPathReference, + public rootOutletState?: OutletStateReference) { } child() { return new DynamicScope( - this.view, this.outletState, this.rootOutletState + this.view, this.outletState, this.rootOutletState, ); } get(key) { + // tslint:disable-next-line:max-line-length assert(`Using \`-get-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); return this.outletState; } set(key, value) { + // tslint:disable-next-line:max-line-length assert(`Using \`-with-dynamic-scope\` is only supported for \`outletState\` (you used \`${key}\`).`, key === 'outletState'); this.outletState = value; return value; @@ -52,18 +58,26 @@ class DynamicScope { } class RootState { - public id: any - public env: any - public root: any - public result: any - public shouldReflush: boolean - public destroyed: boolean - private _removing: boolean - public options: any - public render: any - - constructor(root, env, template, self, parentElement, dynamicScope) { - assert(`You cannot render \`${self.value()}\` without a template.`, template); + public id: string; + public env: Environment; + public root: Opaque; + public result: RenderResult; + public shouldReflush: boolean; + public destroyed: boolean; + public options: { + alwaysRevalidate: boolean; + }; + public render: () => void; + private _removing: boolean; + + constructor( + root: Opaque, + env: Environment, + template: OwnedTemplate, + self: VersionedPathReference, + parentElement: Simple.Element, + dynamicScope: DynamicScope) { + assert(`You cannot render \`${self.value()}\` without a template.`, template !== undefined); this.id = getViewId(root); this.env = env; @@ -74,12 +88,12 @@ class RootState { this._removing = false; let options = this.options = { - alwaysRevalidate: false + alwaysRevalidate: false, }; this.render = () => { let iterator = template.render(self, parentElement, dynamicScope); - let iteratorResult; + let iteratorResult: IteratorResult; do { iteratorResult = iterator.next(); @@ -157,7 +171,7 @@ function loopBegin() { } } -function K() {} +function K() { /* noop */ } let loops = 0; function loopEnd(current, next) { @@ -180,15 +194,17 @@ backburner.on('begin', loopBegin); backburner.on('end', loopEnd); export class Renderer { - private _env: any - private _rootTemplate: any - private _viewRegistry: any - private _destinedForDOM: any - private _destroyed: boolean - private _roots: Array - private _lastRevision: any - private _isRenderingRoots: boolean - private _removedRoots: Array + private _env: Environment; + private _rootTemplate: any; + private _viewRegistry: { + [viewId: string]: Opaque, + }; + private _destinedForDOM: boolean; + private _destroyed: boolean; + private _roots: RootState[]; + private _lastRevision: number; + private _isRenderingRoots: boolean; + private _removedRoots: RootState[]; constructor(env, rootTemplate, _viewRegistry = fallbackViewRegistry, destinedForDOM = false) { this._env = env; @@ -204,7 +220,7 @@ export class Renderer { // renderer HOOKS - appendOutletView(view, target) { + appendOutletView(view: OutletView, target: Simple.Element) { let definition = new TopLevelOutletComponentDefinition(view); let outletStateReference = view.toReference(); let targetObject = view.outletState.render.controller; @@ -212,13 +228,18 @@ export class Renderer { this._appendDefinition(view, definition, target, outletStateReference, targetObject); } - appendTo(view, target) { + appendTo(view: Opaque, target: Simple.Element) { let rootDef = new RootComponentDefinition(view); this._appendDefinition(view, rootDef, target); } - _appendDefinition(root, definition, target, outletStateReference?, targetObject = null) { + _appendDefinition( + root: Opaque, + definition: ComponentDefinition, + target: Simple.Element, + outletStateReference?: OutletStateReference, + targetObject: Opaque = null) { let self = new RootReference(definition); let dynamicScope = new DynamicScope(null, outletStateReference, outletStateReference); let rootState = new RootState(root, this._env, this._rootTemplate, self, target, dynamicScope); @@ -226,11 +247,11 @@ export class Renderer { this._renderRoot(rootState); } - rerender(view) { + rerender() { this._scheduleRevalidate(); } - register(view) { + register(view: Opaque) { let id = getViewId(view); assert('Attempted to register a view with an id already in use: ' + id, !this._viewRegistry[id]); this._viewRegistry[id] = view; @@ -300,7 +321,7 @@ export class Renderer { return this._env.getAppendOperations().createElement(tagName); } - _renderRoot(root) { + _renderRoot(root: RootState) { let { _roots: roots } = this; roots.push(root); diff --git a/packages/ember-glimmer/lib/setup-registry.ts b/packages/ember-glimmer/lib/setup-registry.ts index 1bc494c48e6..8d947a8f24e 100644 --- a/packages/ember-glimmer/lib/setup-registry.ts +++ b/packages/ember-glimmer/lib/setup-registry.ts @@ -1,21 +1,21 @@ -import { environment } from 'ember-environment'; import { privatize as P } from 'container'; -import { InteractiveRenderer, InertRenderer } from './renderer'; +import { environment } from 'ember-environment'; +import Component from './component'; +import Checkbox from './components/checkbox'; +import LinkToComponent from './components/link-to'; +import TextArea from './components/text_area'; +import TextField from './components/text_field'; import { DOMChanges, DOMTreeConstruction, - NodeDOMTreeConstruction + NodeDOMTreeConstruction, } from './dom'; -import OutletView from './views/outlet'; -import TextField from './components/text_field'; -import TextArea from './components/text_area'; -import Checkbox from './components/checkbox'; -import LinkToComponent from './components/link-to'; -import Component from './component'; +import Environment from './environment'; +import { InertRenderer, InteractiveRenderer } from './renderer'; import ComponentTemplate from './templates/component'; -import RootTemplate from './templates/root'; import OutletTemplate from './templates/outlet'; -import Environment from './environment'; +import RootTemplate from './templates/root'; +import OutletView from './views/outlet'; export function setupApplicationRegistry(registry) { registry.injection('service:-glimmer-environment', 'appendOperations', 'service:-dom-tree-construction'); @@ -34,14 +34,14 @@ export function setupApplicationRegistry(registry) { registry.register('service:-dom-changes', { create({ document }) { return new DOMChanges(document); - } + }, }); registry.register('service:-dom-tree-construction', { create({ document }) { - var Implementation = environment.hasDOM ? DOMTreeConstruction : NodeDOMTreeConstruction; + let Implementation = environment.hasDOM ? DOMTreeConstruction : NodeDOMTreeConstruction; return new Implementation(document); - } + }, }); } diff --git a/packages/ember-glimmer/lib/syntax.ts b/packages/ember-glimmer/lib/syntax.ts index 1f0238cea3d..2cb8b1a1e9b 100644 --- a/packages/ember-glimmer/lib/syntax.ts +++ b/packages/ember-glimmer/lib/syntax.ts @@ -1,15 +1,15 @@ -import { renderMacro } from './syntax/render'; -import { outletMacro } from './syntax/outlet'; -import { mountMacro } from './syntax/mount'; +import { assert } from 'ember-debug'; +import { textAreaMacro } from './syntax/-text-area'; import { blockComponentMacro, - inlineComponentMacro + inlineComponentMacro, } from './syntax/dynamic-component'; -import { wrapComponentClassAttribute } from './utils/bindings'; import { inputMacro } from './syntax/input'; -import { textAreaMacro } from './syntax/-text-area'; +import { mountMacro } from './syntax/mount'; +import { outletMacro } from './syntax/outlet'; +import { renderMacro } from './syntax/render'; import { hashToArgs } from './syntax/utils'; -import { assert } from 'ember-debug'; +import { wrapComponentClassAttribute } from './utils/bindings'; function refineInlineSyntax(name, params, hash, builder) { assert(`You attempted to overwrite the built-in helper "${name}" which is not allowed. Please rename the helper.`, !(builder.env.builtInHelpers[name] && builder.env.owner.hasRegistration(`helper:${name}`))); @@ -53,7 +53,7 @@ function refineBlockSyntax(name, params, hash, _default, inverse, builder) { return false; } -export const experimentalMacros: Array = []; +export const experimentalMacros: any[] = []; // This is a private API to allow for experimental macros // to be created in user space. Registering a macro should diff --git a/packages/ember-glimmer/lib/syntax/dynamic-component.ts b/packages/ember-glimmer/lib/syntax/dynamic-component.ts index 4969d6b87a0..ef1a30ea6b1 100644 --- a/packages/ember-glimmer/lib/syntax/dynamic-component.ts +++ b/packages/ember-glimmer/lib/syntax/dynamic-component.ts @@ -1,5 +1,5 @@ import { - isComponentDefinition + isComponentDefinition, } from '@glimmer/runtime'; import { assert } from 'ember-debug'; import { hashToArgs } from './utils'; diff --git a/packages/ember-glimmer/lib/syntax/input.ts b/packages/ember-glimmer/lib/syntax/input.ts index 5e21514f545..80313a3a613 100644 --- a/packages/ember-glimmer/lib/syntax/input.ts +++ b/packages/ember-glimmer/lib/syntax/input.ts @@ -171,7 +171,7 @@ export function inputMacro(name, params, hash, builder) { assert( '{{input type=\'checkbox\'}} does not support setting `value=someBooleanValue`; ' + 'you must use `checked=someBooleanValue` instead.', - valueIndex === -1 + valueIndex === -1, ); wrapComponentClassAttribute(hash); return buildSyntax('-checkbox', params, hash, builder); diff --git a/packages/ember-glimmer/lib/syntax/mount.ts b/packages/ember-glimmer/lib/syntax/mount.ts index 6080ea415aa..ef9d28448fb 100644 --- a/packages/ember-glimmer/lib/syntax/mount.ts +++ b/packages/ember-glimmer/lib/syntax/mount.ts @@ -4,8 +4,8 @@ import { assert } from 'ember-debug'; import { DEBUG } from 'ember-env-flags'; import { EMBER_ENGINES_MOUNT_PARAMS } from 'ember/features'; -import { hashToArgs } from './utils'; import { MountDefinition } from '../component-managers/mount'; +import { hashToArgs } from './utils'; function dynamicEngineFor(vm, args, meta) { let env = vm.env; @@ -59,12 +59,12 @@ export function mountMacro(name, params, hash, builder) { if (EMBER_ENGINES_MOUNT_PARAMS) { assert( 'You can only pass a single positional argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.', - params.length === 1 + params.length === 1, ); } else { assert( 'You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.', - params.length === 1 && hash === null + params.length === 1 && hash === null, ); } @@ -91,7 +91,7 @@ class DynamicEngineReference { } value() { - let { env, nameRef, /*meta*/ } = this; + let { env, nameRef /*meta*/ } = this; let nameOrDef = nameRef.value(); if (typeof nameOrDef === 'string') { @@ -101,7 +101,7 @@ class DynamicEngineReference { assert( `You used \`{{mount '${nameOrDef}'}}\`, but the engine '${nameOrDef}' can not be found.`, - env.owner.hasRegistration(`engine:${nameOrDef}`) + env.owner.hasRegistration(`engine:${nameOrDef}`), ); if (!env.owner.hasRegistration(`engine:${nameOrDef}`)) { @@ -115,7 +115,7 @@ class DynamicEngineReference { } else { assert( `Invalid engine name '${nameOrDef}' specified, engine name must be either a string, null or undefined.`, - nameOrDef === null || nameOrDef === undefined + nameOrDef === null || nameOrDef === undefined, ); return null; diff --git a/packages/ember-glimmer/lib/syntax/outlet.ts b/packages/ember-glimmer/lib/syntax/outlet.ts index 5d4c2bc7a34..e99a726ef0e 100644 --- a/packages/ember-glimmer/lib/syntax/outlet.ts +++ b/packages/ember-glimmer/lib/syntax/outlet.ts @@ -1,8 +1,8 @@ import { - UpdatableTag, + combine, ConstReference, TagWrapper, - combine + UpdatableTag, } from '@glimmer/reference'; import { OutletComponentDefinition } from '../component-managers/outlet'; diff --git a/packages/ember-glimmer/lib/syntax/render.ts b/packages/ember-glimmer/lib/syntax/render.ts index 4d645329bdb..87cbef380f7 100644 --- a/packages/ember-glimmer/lib/syntax/render.ts +++ b/packages/ember-glimmer/lib/syntax/render.ts @@ -4,12 +4,12 @@ import { ConstReference, isConst } from '@glimmer/reference'; import { assert } from 'ember-debug'; -import { hashToArgs } from './utils'; import { + NON_SINGLETON_RENDER_MANAGER, RenderDefinition, SINGLETON_RENDER_MANAGER, - NON_SINGLETON_RENDER_MANAGER } from '../component-managers/render'; +import { hashToArgs } from './utils'; function makeComponentDefinition(vm, args) { let env = vm.env; @@ -45,7 +45,6 @@ function makeComponentDefinition(vm, args) { } } - /** Calling ``{{render}}`` from within a template will insert another template that matches the provided name. The inserted template will diff --git a/packages/ember-glimmer/lib/syntax/utils.ts b/packages/ember-glimmer/lib/syntax/utils.ts index cb3558966d2..000e36a65cb 100644 --- a/packages/ember-glimmer/lib/syntax/utils.ts +++ b/packages/ember-glimmer/lib/syntax/utils.ts @@ -1,5 +1,5 @@ export function hashToArgs(hash) { - if (hash === null) return null; - let names = hash[0].map(key => `@${key}`); + if (hash === null) { return null; } + let names = hash[0].map((key) => `@${key}`); return [names, hash[1]]; } diff --git a/packages/ember-glimmer/lib/template.ts b/packages/ember-glimmer/lib/template.ts index 96a57abb822..d58fda7906f 100644 --- a/packages/ember-glimmer/lib/template.ts +++ b/packages/ember-glimmer/lib/template.ts @@ -1,14 +1,44 @@ +import { + Template, + templateFactory, + TemplateFactory, +} from '@glimmer/runtime'; import { OWNER } from 'ember-utils'; -import { templateFactory } from '@glimmer/runtime'; -export default function template(json) { - const factory = templateFactory(json); - - return { - id: factory.id, - meta: factory.meta, - create(props) { - return factory.create(props.env, { owner: props[OWNER] }); - } +export interface Container { + lookup(name: string): T; +} + +export type OwnedTemplate = Template<{ + moduleName: string; + owner: Container; +}>; + +class WrappedTemplateFactory { + id: string; + meta: { + moduleName: string; }; + constructor(public factory: TemplateFactory<{ + moduleName: string; + }, { + owner: Container; + }>) { + this.id = factory.id; + this.meta = factory.meta; + } + + create(props: any): OwnedTemplate { + let owner = props[OWNER]; + return this.factory.create(props.env, { owner }); + } +} + +export default function template(json) { + const factory = templateFactory<{ + moduleName: string; + }, { + owner: Container; + }>(json); + return new WrappedTemplateFactory(factory); } diff --git a/packages/ember-glimmer/lib/template_registry.ts b/packages/ember-glimmer/lib/template_registry.ts index c39f8472a98..1cb5fdfbc3a 100644 --- a/packages/ember-glimmer/lib/template_registry.ts +++ b/packages/ember-glimmer/lib/template_registry.ts @@ -17,7 +17,7 @@ export function getTemplate(name) { } } -export function hasTemplate(name):boolean { +export function hasTemplate(name): boolean { return TEMPLATES.hasOwnProperty(name); } diff --git a/packages/ember-glimmer/lib/utils/bindings.ts b/packages/ember-glimmer/lib/utils/bindings.ts index 695e8714fcb..dd34df2e8cc 100644 --- a/packages/ember-glimmer/lib/utils/bindings.ts +++ b/packages/ember-glimmer/lib/utils/bindings.ts @@ -1,14 +1,14 @@ +import { Opaque, Option } from '@glimmer/interfaces'; import { CachedReference, combine, map, - referenceFromParts, Reference, - Tag + referenceFromParts, + Tag, } from '@glimmer/reference'; -import { Opaque, Option } from '@glimmer/interfaces'; import { - Ops + Ops, } from '@glimmer/wire-format'; import { assert } from 'ember-debug'; import { get } from 'ember-metal'; @@ -97,7 +97,7 @@ export const AttributeBinding = { } operations.addDynamicAttribute(element, attribute, reference); - } + }, }; const DISPLAY_NONE = 'display: none;'; @@ -133,7 +133,7 @@ export const IsVisibleBinding = { mapStyleValue(isVisible) { return isVisible === false ? SAFE_DISPLAY_NONE : null; - } + }, }; export const ClassNameBinding = { @@ -157,7 +157,7 @@ export const ClassNameBinding = { operations.addDynamicAttribute(element, 'class', ref); } - } + }, }; class SimpleClassNameBindingReference extends CachedReference> { diff --git a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts index 3f7b851da2b..e19b4bb1850 100644 --- a/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts +++ b/packages/ember-glimmer/lib/utils/curly-component-state-bucket.ts @@ -7,7 +7,12 @@ interface Environment { } interface Component { + _debugContainerKey: string; trigger(event: string); + destroy(): void; + setProperties(props: { + [key: string]: any; + }): void; } type Finalizer = () => void; @@ -25,9 +30,9 @@ function NOOP() {} */ export default class ComponentStateBucket { public classRef: Opaque = null; - private argsRevision: Revision; + public argsRevision: Revision; - constructor(private environment: Environment, private component: Component, private args: Tagged, private finalizer: Finalizer) { + constructor(public environment: Environment, public component: Component, public args: Tagged, public finalizer: Finalizer) { this.classRef = null; this.argsRevision = args.tag.value(); } diff --git a/packages/ember-glimmer/lib/utils/iterable.ts b/packages/ember-glimmer/lib/utils/iterable.ts index bed9be71401..ba82dd2274f 100644 --- a/packages/ember-glimmer/lib/utils/iterable.ts +++ b/packages/ember-glimmer/lib/utils/iterable.ts @@ -1,22 +1,22 @@ -import { guidFor } from 'ember-utils'; -import { get, tagForProperty, tagFor, isProxy } from 'ember-metal'; -import { - objectAt, - isEmberArray -} from 'ember-runtime'; -import { - UpdatableReference, - UpdatablePrimitiveReference -} from './references'; -import { isEachIn } from '../helpers/each-in'; import { + combine, CONSTANT_TAG, IterationItem, TagWrapper, UpdatableTag, - combine } from '@glimmer/reference'; import { Opaque } from '@glimmer/util'; +import { get, isProxy, tagFor, tagForProperty } from 'ember-metal'; +import { + isEmberArray, + objectAt, +} from 'ember-runtime'; +import { guidFor } from 'ember-utils'; +import { isEachIn } from '../helpers/each-in'; +import { + UpdatablePrimitiveReference, + UpdatableReference, +} from './references'; const ITERATOR_KEY_GUID = 'be277757-bbbe-4620-9fcb-213ef433cca2'; @@ -82,7 +82,7 @@ function ensureUniqueKey(seen, key) { } class ArrayIterator { - public array: Array; + public array: any[]; public length: number; public keyFor: (value: any, memo: any) => any; public position: number; @@ -135,7 +135,7 @@ class EmberArrayIterator extends ArrayIterator { } class ObjectKeysIterator extends ArrayIterator { - public keys: Array; + public keys: any[]; public length: number; constructor(keys, values, keyFor) { @@ -190,7 +190,7 @@ class EachInIterable { if (iterable !== null && (typeofIterable === 'object' || typeofIterable === 'function')) { let keys = Object.keys(iterable); - let values = keys.map(key => iterable[key]); + let values = keys.map((key) => iterable[key]); return keys.length > 0 ? new ObjectKeysIterator(keys, values, keyFor) : EMPTY_ITERATOR; } else { return EMPTY_ITERATOR; @@ -248,7 +248,7 @@ class ArrayIterable { } else if (isEmberArray(iterable)) { return get(iterable, 'length') > 0 ? new EmberArrayIterator(iterable, keyFor) : EMPTY_ITERATOR; } else if (typeof iterable.forEach === 'function') { - let array: Array = []; + let array: any[] = []; iterable.forEach(function(item) { array.push(item); }); diff --git a/packages/ember-glimmer/lib/utils/process-args.ts b/packages/ember-glimmer/lib/utils/process-args.ts index 3c9cdb8848e..6b9a929f696 100644 --- a/packages/ember-glimmer/lib/utils/process-args.ts +++ b/packages/ember-glimmer/lib/utils/process-args.ts @@ -1,8 +1,8 @@ import { symbol } from 'ember-utils'; -import { ARGS } from '../component'; -import { UPDATE } from './references'; import { MUTABLE_CELL } from 'ember-views'; +import { ARGS } from '../component'; import { ACTION } from '../helpers/action'; +import { UPDATE } from './references'; // ComponentArgs takes EvaluatedNamedArgs and converts them into the // inputs needed by CurlyComponents (attrs and props, with mutable diff --git a/packages/ember-glimmer/lib/utils/references.ts b/packages/ember-glimmer/lib/utils/references.ts index 627a337c779..2dd02ae0a21 100644 --- a/packages/ember-glimmer/lib/utils/references.ts +++ b/packages/ember-glimmer/lib/utils/references.ts @@ -1,39 +1,39 @@ import { - HAS_NATIVE_WEAKMAP, - Opaque, - symbol -} from 'ember-utils'; -import { - get, - set, - tagForProperty, - tagFor, - didRender, - watchKey, - isProxy -} from 'ember-metal'; -import { + combine, CONSTANT_TAG, ConstReference, DirtyableTag, - UpdatableTag, + isConst, TagWrapper, + UpdatableTag, VersionedPathReference, - combine, - isConst } from '@glimmer/reference'; import { ConditionalReference as GlimmerConditionalReference, - PrimitiveReference + PrimitiveReference, } from '@glimmer/runtime'; -import emberToBool from './to-bool'; -import { RECOMPUTE_TAG } from '../helper'; import { DEBUG } from 'ember-env-flags'; import { - EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER, + didRender, + get, + isProxy, + set, + tagFor, + tagForProperty, + watchKey, +} from 'ember-metal'; +import { + HAS_NATIVE_WEAKMAP, + Opaque, + symbol, +} from 'ember-utils'; +import { EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER, - MANDATORY_SETTER + EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER, + MANDATORY_SETTER, } from 'ember/features'; +import { RECOMPUTE_TAG } from '../helper'; +import emberToBool from './to-bool'; export const UPDATE = symbol('UPDATE'); @@ -50,7 +50,7 @@ if (DEBUG) { if (!Object.isFrozen(obj) && HAS_NATIVE_WEAKMAP) { Object.freeze(obj); } - } + }; } // @abstract @@ -93,9 +93,10 @@ export class CachedReference extends EmberPathReference { } // @implements PathReference -export class RootReference extends ConstReference { +export class RootReference extends ConstReference { public children: any; - constructor(value) { + + constructor(value: T) { super(value); this.children = Object.create(null); } diff --git a/packages/ember-glimmer/lib/utils/string.ts b/packages/ember-glimmer/lib/utils/string.ts index c3a078edbf3..af50fbf9782 100644 --- a/packages/ember-glimmer/lib/utils/string.ts +++ b/packages/ember-glimmer/lib/utils/string.ts @@ -27,8 +27,8 @@ export function getSafeString() { { id: 'ember-htmlbars.ember-handlebars-safestring', until: '3.0.0', - url: 'https://emberjs.com/deprecations/v2.x#toc_use-ember-string-htmlsafe-over-ember-handlebars-safestring' - } + url: 'https://emberjs.com/deprecations/v2.x#toc_use-ember-string-htmlsafe-over-ember-handlebars-safestring', + }, ); return SafeString; @@ -43,7 +43,7 @@ const escape = { "'": ''', // jscs:enable '`': '`', - '=': '=' + '=': '=', }; const possible = /[&<>"'`=]/; diff --git a/packages/ember-glimmer/lib/utils/to-bool.ts b/packages/ember-glimmer/lib/utils/to-bool.ts index ce7bac57728..de09e00524b 100644 --- a/packages/ember-glimmer/lib/utils/to-bool.ts +++ b/packages/ember-glimmer/lib/utils/to-bool.ts @@ -1,5 +1,5 @@ -import { isArray } from 'ember-runtime'; import { get } from 'ember-metal'; +import { isArray } from 'ember-runtime'; export default function toBool(predicate) { if (!predicate) { diff --git a/packages/ember-glimmer/lib/views/outlet.ts b/packages/ember-glimmer/lib/views/outlet.ts index 0cd4ef80dc3..26f080d8a1d 100644 --- a/packages/ember-glimmer/lib/views/outlet.ts +++ b/packages/ember-glimmer/lib/views/outlet.ts @@ -1,31 +1,32 @@ -import { assign } from 'ember-utils'; -import { DirtyableTag } from '@glimmer/reference'; +import { Simple } from '@glimmer/interfaces'; +import { DirtyableTag, VersionedPathReference } from '@glimmer/reference'; import { environment } from 'ember-environment'; -import { OWNER } from 'ember-utils'; import { run } from 'ember-metal'; +import { assign } from 'ember-utils'; +import { OWNER } from 'ember-utils'; +import Environment from '../environment'; +import { Renderer } from '../renderer'; -class OutletStateReference { - public outletView: any; +export class OutletStateReference implements VersionedPathReference { public tag: any; - constructor(outletView) { - this.outletView = outletView; + constructor(public outletView: OutletView) { this.tag = outletView._tag; } - get(key) { + get(key: string): VersionedPathReference { return new ChildOutletStateReference(this, key); } - value() { + value(): OutletState { return this.outletView.outletState; } - getOrphan(name) { + getOrphan(name: string): VersionedPathReference { return new OrphanedOutletStateReference(this, name); } - update(state) { + update(state: OutletState) { this.outletView.setOutletState(state); } } @@ -43,7 +44,7 @@ class OrphanedOutletStateReference extends OutletStateReference { this.name = name; } - value() { + value(): OutletState { let rootState = this.root.value(); let orphans = rootState.outlets.main.outlets.__ember_orphans__; @@ -61,7 +62,7 @@ class OrphanedOutletStateReference extends OutletStateReference { let state = Object.create(null); state[matched.render.outlet] = matched; matched.wasUsed = true; - return { outlets: state }; + return { outlets: state, render: undefined }; } } @@ -85,13 +86,28 @@ class ChildOutletStateReference { } } +export interface OutletState { + outlets: { + [name: string]: OutletState; + }; + render: { + owner: any | undefined, + into: string, + outlet: string, + name: string, + controller: any | undefined, + ViewClass: Function | undefined, + template: any | undefined, + }; +} + export default class OutletView { - private _environment: any; - public renderer: any; + private _environment: Environment; + public renderer: Renderer; public owner: any; public template: any; - public outletState: any; - private _tag: any; + public outletState: OutletState; + public _tag: DirtyableTag; static extend(injections) { return class extends OutletView { @@ -124,7 +140,7 @@ export default class OutletView { this._tag = new DirtyableTag(); } - appendTo(selector) { + appendTo(selector: string | Simple.Element) { let env = this._environment || environment; let target; @@ -139,10 +155,10 @@ export default class OutletView { rerender() { } - setOutletState(state) { + setOutletState(state: OutletState) { this.outletState = { outlets: { - main: state + main: state, }, render: { owner: undefined, @@ -151,8 +167,8 @@ export default class OutletView { name: '-top-level', controller: undefined, ViewClass: undefined, - template: undefined - } + template: undefined, + }, }; this._tag.dirty(); } diff --git a/yarn.lock b/yarn.lock index 7a3b48e852e..4022d73c8a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -186,6 +186,12 @@ ansi-styles@^2.0.1, ansi-styles@^2.1.0, ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" +ansi-styles@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" + dependencies: + color-convert "^1.9.0" + ansicolors@~0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.2.1.tgz#be089599097b74a5c9c4a84a0cdbcdb62bd87aef" @@ -1393,7 +1399,7 @@ buffer@4.9.1: ieee754 "^1.1.4" isarray "^1.0.0" -builtin-modules@^1.0.0: +builtin-modules@^1.0.0, builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -1519,6 +1525,14 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" +chalk@^2.1.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + charm@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/charm/-/charm-1.0.2.tgz#8add367153a6d9a581331052c4090991da995e35" @@ -1626,6 +1640,16 @@ code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" +color-convert@^1.9.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + colors@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" @@ -2031,6 +2055,10 @@ diff@1.4.0, diff@^1.3.1: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" +diff@^3.2.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" + doctrine@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" @@ -3267,6 +3295,10 @@ has-cors@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" +has-flag@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" + has-unicode@^2.0.0, has-unicode@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" @@ -4294,7 +4326,7 @@ minimatch@0.3: lru-cache "2" sigmund "~1.0.0" -"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3: +"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" dependencies: @@ -5329,6 +5361,12 @@ resolve@^1.1.2, resolve@^1.1.6, resolve@^1.3.3: dependencies: path-parse "^1.0.5" +resolve@^1.3.2: + version "1.5.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36" + dependencies: + path-parse "^1.0.5" + restore-cursor@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" @@ -5834,6 +5872,12 @@ supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" +supports-color@^4.0.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b" + dependencies: + has-flag "^2.0.0" + symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8: version "1.1.8" resolved "https://registry.yarnpkg.com/symlink-or-copy/-/symlink-or-copy-1.1.8.tgz#cabe61e0010c1c023c173b25ee5108b37f4b4aa3" @@ -6002,6 +6046,32 @@ tryor@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/tryor/-/tryor-0.1.2.tgz#8145e4ca7caff40acde3ccf946e8b8bb75b4172b" +tslib@^1.7.1: + version "1.8.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6" + +tslint@^5.8.0: + version "5.8.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.8.0.tgz#1f49ad5b2e77c76c3af4ddcae552ae4e3612eb13" + dependencies: + babel-code-frame "^6.22.0" + builtin-modules "^1.1.1" + chalk "^2.1.0" + commander "^2.9.0" + diff "^3.2.0" + glob "^7.1.1" + minimatch "^3.0.4" + resolve "^1.3.2" + semver "^5.3.0" + tslib "^1.7.1" + tsutils "^2.12.1" + +tsutils@^2.12.1: + version "2.12.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.12.1.tgz#f4d95ce3391c8971e46e54c4cf0edb0a21dd5b24" + dependencies: + tslib "^1.7.1" + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"