Skip to content

Commit

Permalink
Merge pull request #16399 from emberjs/iterable-refactor
Browse files Browse the repository at this point in the history
Iterable refactor
  • Loading branch information
krisselden authored Mar 24, 2018
2 parents bec7eb6 + 1d0ef5f commit c2e1f40
Show file tree
Hide file tree
Showing 15 changed files with 473 additions and 363 deletions.
6 changes: 3 additions & 3 deletions packages/ember-glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
WithDynamicTagName,
WithStaticLayout,
} from '@glimmer/runtime';
import { Destroyable, EMPTY_ARRAY, Opaque } from '@glimmer/util';
import { Destroyable, EMPTY_ARRAY } from '@glimmer/util';
import { privatize as P } from 'container';
import {
assert,
Expand Down Expand Up @@ -206,7 +206,7 @@ export default class CurlyComponentManager extends AbstractManager<ComponentStat
* features like exposed by view mixins like ChildViewSupport, ActionSupport,
* etc.
*/
create(environment: Environment, state: DefinitionState, args: Arguments, dynamicScope: DynamicScope, callerSelfRef: VersionedPathReference<Opaque>, hasBlock: boolean): ComponentStateBucket {
create(environment: Environment, state: DefinitionState, args: Arguments, dynamicScope: DynamicScope, callerSelfRef: VersionedPathReference, hasBlock: boolean): ComponentStateBucket {
if (DEBUG) {
this._pushToDebugStack(`component:${state.name}`, environment);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ export default class CurlyComponentManager extends AbstractManager<ComponentStat
return bucket;
}

getSelf({ component }: ComponentStateBucket): VersionedPathReference<Opaque> {
getSelf({ component }: ComponentStateBucket): VersionedPathReference {
return component[ROOT_REF];
}

Expand Down
18 changes: 8 additions & 10 deletions packages/ember-glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
Reference,
OpaqueIterable, VersionedReference,
} from '@glimmer/reference';
import {
ElementBuilder,
Environment as GlimmerEnvironment,
PrimitiveReference,
SimpleDynamicAttribute,
} from '@glimmer/runtime';
import {
Expand All @@ -21,7 +20,6 @@ import DebugStack from './utils/debug-stack';
import createIterable from './utils/iterable';
import {
ConditionalReference,
RootPropertyReference,
UpdatableReference,
} from './utils/references';
import { isHTMLSafe } from './utils/string';
Expand All @@ -45,7 +43,7 @@ export default class Environment extends GlimmerEnvironment {
public destroyedComponents: Destroyable[];

public debugStack: typeof DebugStack;
public inTransaction: boolean;
public inTransaction = false;

constructor(injections: any) {
super(injections);
Expand All @@ -72,11 +70,11 @@ export default class Environment extends GlimmerEnvironment {
return lookupComponent(meta.owner, name, meta);
}

toConditionalReference(reference: UpdatableReference): ConditionalReference | RootPropertyReference | PrimitiveReference<any> {
toConditionalReference(reference: UpdatableReference): VersionedReference<boolean> {
return ConditionalReference.create(reference);
}

iterableFor(ref: Reference<Opaque>, key: string) {
iterableFor(ref: VersionedReference, key: string): OpaqueIterable {
return createIterable(ref, key);
}

Expand All @@ -86,23 +84,23 @@ export default class Environment extends GlimmerEnvironment {
}
}

scheduleUpdateModifier(modifier: any, manager: any) {
scheduleUpdateModifier(modifier: any, manager: any): void {
if (this.isInteractive) {
super.scheduleUpdateModifier(modifier, manager);
}
}

didDestroy(destroyable: Destroyable) {
didDestroy(destroyable: Destroyable): void {
destroyable.destroy();
}

begin() {
begin(): void {
this.inTransaction = true;

super.begin();
}

commit() {
commit(): void {
let destroyedComponents = this.destroyedComponents;
this.destroyedComponents = [];
// components queued for destruction must be destroyed before firing
Expand Down
27 changes: 22 additions & 5 deletions packages/ember-glimmer/lib/helpers/each-in.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
@module ember
*/
import { Tag, VersionedPathReference } from '@glimmer/reference';
import {
Arguments,
VM
} from '@glimmer/runtime';
import { Opaque } from '@glimmer/util';
import { symbol } from 'ember-utils';

/**
Expand Down Expand Up @@ -115,12 +117,27 @@ import { symbol } from 'ember-utils';
*/
const EACH_IN_REFERENCE = symbol('EACH_IN');

export function isEachIn(ref: any): boolean {
return ref && ref[EACH_IN_REFERENCE];
class EachInReference implements VersionedPathReference {
public tag: Tag;

constructor(private inner: VersionedPathReference) {
this.tag = inner.tag;
this[EACH_IN_REFERENCE] = true;
}

value(): Opaque {
return this.inner.value();
}

get(key: string): VersionedPathReference {
return this.inner.get(key);
}
}

export function isEachIn(ref: Opaque): ref is VersionedPathReference {
return ref !== null && typeof ref === 'object' && ref[EACH_IN_REFERENCE];
}

export default function(_vm: VM, args: Arguments) {
let ref = Object.create(args.positional.at(0));
ref[EACH_IN_REFERENCE] = true;
return ref;
return new EachInReference(args.positional.at(0));
}
Loading

0 comments on commit c2e1f40

Please sign in to comment.