Skip to content

Commit

Permalink
fix: the projection plumbing via scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayan751 committed Jul 12, 2020
1 parent 25dcc83 commit e79194b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
4 changes: 3 additions & 1 deletion packages/jit-html/src/template-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import {
BindingMode,
Bindable,
CustomElement,
IProjections,
SlotInfo,
AuSlotContentType,
} from '@aurelia/runtime';
import {
HTMLAttributeInstruction,
Expand All @@ -60,7 +63,6 @@ import {
TemplateControllerSymbol,
TextSymbol
} from './semantic-model';
import { IProjections, SlotInfo, AuSlotContentType } from '@aurelia/runtime/dist/resources/custom-elements/au-slot';

class CustomElementCompilationUnit {
public readonly instructions: ITargetedInstruction[][] = [];
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export {

export {
AuSlot,
IProjections,
SlotInfo,
AuSlotContentType,
} from './resources/custom-elements/au-slot';

export {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/observation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export interface IScope {
readonly bindingContext: IBindingContext;
readonly overrideContext: IOverrideContext;
readonly isComponentScope: boolean;
readonly providedProjections: WeakMap<ITargetedInstruction, IProjections> | null;
providedProjections: WeakMap<ITargetedInstruction, IProjections> | null;
}

export type ObserversLookup = IIndexable<{
Expand Down
11 changes: 5 additions & 6 deletions packages/runtime/src/observation/binding-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ export class BindingContext implements IBindingContext {
export class Scope implements IScope {
public parentScope: IScope | null;
public scopeParts: readonly string[];
public projections: readonly CustomElementDefinition[];
public projections: readonly CustomElementDefinition[]; // TODO remove
public bindingContext: IBindingContext;
public overrideContext: IOverrideContext;

private constructor(
parentScope: IScope | null,
bindingContext: IBindingContext,
overrideContext: IOverrideContext,
public readonly providedProjections: WeakMap<ITargetedInstruction, IProjections> | null,
public providedProjections: WeakMap<ITargetedInstruction, IProjections> | null,
public readonly isComponentScope: boolean,
) {
this.parentScope = parentScope;
Expand Down Expand Up @@ -207,7 +207,7 @@ export class Scope implements IScope {
* during binding, it will traverse up via the `parentOverrideContext` of the `OverrideContext` until
* it finds the property.
*/
public static create(flags: LifecycleFlags, bc: object, oc: IOverrideContext, providedProjections: WeakMap<ITargetedInstruction, IProjections> | null, isComponentScope?: boolean): Scope;
public static create(flags: LifecycleFlags, bc: object, oc: IOverrideContext, isComponentScope?: boolean): Scope;
/**
* Create a new `Scope` backed by the provided `BindingContext` and `OverrideContext`.
*
Expand All @@ -217,15 +217,14 @@ export class Scope implements IScope {
* @param bc - The `BindingContext` to back the `Scope` with.
* @param oc - null. This overload is functionally equivalent to not passing this argument at all.
*/
public static create(flags: LifecycleFlags, bc: object, oc: null, providedProjections?: WeakMap<ITargetedInstruction, IProjections> | null, isComponentScope?: boolean): Scope;
public static create(flags: LifecycleFlags, bc: object, oc: null, isComponentScope?: boolean): Scope;
public static create(
flags: LifecycleFlags,
bc: object,
oc?: IOverrideContext | null,
providedProjections: WeakMap<ITargetedInstruction, IProjections> | null = null,
isComponentScope: boolean = false
): Scope {
return new Scope(null, bc as IBindingContext, oc == null ? OverrideContext.create(flags, bc, oc as null) : oc, providedProjections, isComponentScope);
return new Scope(null, bc as IBindingContext, oc == null ? OverrideContext.create(flags, bc, oc as null) : oc, null, isComponentScope);
}

public static fromOverride(flags: LifecycleFlags, oc: IOverrideContext): Scope {
Expand Down
7 changes: 3 additions & 4 deletions packages/runtime/src/resources/custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
fromAnnotationOrDefinitionOrTypeOrDefault,
Injectable,
IResolver,
mergeObjects,
} from '@aurelia/kernel';
import {
registerAliases,
Expand Down Expand Up @@ -276,7 +275,7 @@ export class CustomElementDefinition<T extends Constructable = Constructable> im
mergeArrays(def.scopeParts),
fromDefinitionOrDefault('enhance', def, () => false),
mergeArrays(def.projections),
mergeObjects(def.projectionsMap!),
fromDefinitionOrDefault('projectionsMap', def as CustomElementDefinition, () => null),
);
}

Expand Down Expand Up @@ -316,7 +315,7 @@ export class CustomElementDefinition<T extends Constructable = Constructable> im
mergeArrays(CustomElement.getAnnotation(Type, 'scopeParts'), Type.scopeParts),
fromAnnotationOrTypeOrDefault('enhance', Type, () => false),
mergeArrays(CustomElement.getAnnotation(Type, 'projections'), Type.projections),
mergeObjects(CustomElement.getAnnotation(Type, 'projectionsMap')!, Type.projectionsMap!),
fromAnnotationOrTypeOrDefault('projectionsMap', Type, () => null),
);
}

Expand Down Expand Up @@ -361,7 +360,7 @@ export class CustomElementDefinition<T extends Constructable = Constructable> im
mergeArrays(CustomElement.getAnnotation(Type, 'scopeParts'), nameOrDef.scopeParts, Type.scopeParts),
fromAnnotationOrDefinitionOrTypeOrDefault('enhance', nameOrDef, Type, () => false),
mergeArrays(CustomElement.getAnnotation(Type, 'projections'), nameOrDef.projections, Type.projections),
mergeObjects(CustomElement.getAnnotation(Type, 'projectionsMap')!, nameOrDef.projectionsMap!, Type.projectionsMap!),
fromAnnotationOrDefinitionOrTypeOrDefault('projectionsMap', nameOrDef, Type, () => null),
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/src/templating/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class Controller<
createObservers(this.lifecycle, definition, flags, instance);
createChildrenObservers(this as unknown as IDryCustomElementController<T, NonNullable<C>>, definition, flags, instance);

this.scope = Scope.create(flags, this.bindingContext!, null, definition.projectionsMap, true);
const scope = this.scope = Scope.create(flags, this.bindingContext!, null, true);

const hooks = this.hooks;
if (hooks.hasCreate) {
Expand Down Expand Up @@ -349,6 +349,7 @@ export class Controller<
const compiledContext = context.compile(targetedProjections);
const compiledDefinition = compiledContext.compiledDefinition;

scope.providedProjections = compiledDefinition.projectionsMap;
this.scopeParts = compiledDefinition.scopeParts;
this.projections = compiledDefinition.projections;
this.isStrictBinding = compiledDefinition.isStrictBinding;
Expand Down

0 comments on commit e79194b

Please sign in to comment.