Skip to content

Commit

Permalink
[REFACTOR] Upstreams basic manager infrastructure and types
Browse files Browse the repository at this point in the history
Upstreams the basic manager infrastructure and types to Ember. This will
be followed by upstreaming the respective managers for each type, along
with some of the base managers.

Breaking Changes:

- Renamed `ComponentManager` -> `InternalCompnoentManager`
- Renamed `ModifierManager` -> `InternalModifierManager`
- Upstreamed manager types from Ember
- Upstreamed `setManager` and `getManager` functions from Ember
- Upstreamed `buildCapabilities` from Ember
  • Loading branch information
Chris Garrett committed Nov 13, 2020
1 parent d3d097d commit bff1273
Show file tree
Hide file tree
Showing 43 changed files with 1,188 additions and 283 deletions.
14 changes: 9 additions & 5 deletions packages/@glimmer/benchmark-env/src/benchmark/create-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
ModifierDefinition,
ComponentDefinition,
CompileTimeComponent,
ComponentManager,
InternalComponentManager,
SerializedTemplateWithLazyBlock,
ModifierManager,
InternalModifierManager,
CompilableProgram,
Dict,
PartialDefinition,
Expand Down Expand Up @@ -51,7 +51,7 @@ export interface Registry {
name: string,
template: SerializedTemplateWithLazyBlock,
component: T,
manager: ComponentManager<unknown, T>
manager: InternalComponentManager<unknown, T>
): void;
/**
* Register a helper
Expand All @@ -64,7 +64,11 @@ export interface Registry {
* @param name
* @param helper
*/
registerModifier<T>(name: string, modifier: T, manager: ModifierManager<unknown, T>): void;
registerModifier<T>(
name: string,
modifier: T,
manager: InternalModifierManager<unknown, T>
): void;

render(
entry: string,
Expand All @@ -90,7 +94,7 @@ export default function createRegistry(): Registry {
name: string,
template: SerializedTemplateWithLazyBlock,
component: unknown = null,
manager: ComponentManager = new SimpleComponentManager()
manager: InternalComponentManager = new SimpleComponentManager()
) => {
components.set(
name,
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/benchmark-env/src/benchmark/on-modifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModifierManager, VMArguments } from '@glimmer/interfaces';
import { InternalModifierManager, VMArguments } from '@glimmer/interfaces';
import { Reference, valueForRef } from '@glimmer/reference';
import { castToBrowser } from '@glimmer/util';
import { createUpdatableTag } from '@glimmer/validator';
Expand All @@ -12,7 +12,7 @@ interface OnModifierState {
listener: EventListener | null;
}

class OnModifierManager implements ModifierManager<OnModifierState, null> {
class OnModifierManager implements InternalModifierManager<OnModifierState, null> {
create(element: SimpleElement, _: null, args: VMArguments) {
return {
element,
Expand Down Expand Up @@ -56,6 +56,6 @@ class OnModifierManager implements ModifierManager<OnModifierState, null> {
}
}

const onModifier: ModifierManager<unknown, null> = new OnModifierManager();
const onModifier: InternalModifierManager<unknown, null> = new OnModifierManager();

export default onModifier;
18 changes: 11 additions & 7 deletions packages/@glimmer/integration-tests/lib/components/capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentCapabilities } from '@glimmer/interfaces';
import { InternalComponentCapabilities } from '@glimmer/interfaces';
import { assign } from '@glimmer/util';

export const TEMPLATE_ONLY_CAPABILITIES: ComponentCapabilities = {
export const TEMPLATE_ONLY_CAPABILITIES: InternalComponentCapabilities = {
dynamicLayout: false,
dynamicTag: false,
prepareArgs: false,
Expand All @@ -16,7 +16,7 @@ export const TEMPLATE_ONLY_CAPABILITIES: ComponentCapabilities = {
willDestroy: false,
};

export const CURLY_CAPABILITIES: ComponentCapabilities = {
export const CURLY_CAPABILITIES: InternalComponentCapabilities = {
dynamicLayout: true,
dynamicTag: true,
prepareArgs: true,
Expand All @@ -31,7 +31,11 @@ export const CURLY_CAPABILITIES: ComponentCapabilities = {
willDestroy: true,
};

export const EMBERISH_CURLY_CAPABILITIES: ComponentCapabilities = assign({}, CURLY_CAPABILITIES, {
dynamicLayout: false,
attributeHook: false,
});
export const EMBERISH_CURLY_CAPABILITIES: InternalComponentCapabilities = assign(
{},
CURLY_CAPABILITIES,
{
dynamicLayout: false,
attributeHook: false,
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ElementOperations,
Destroyable,
Dict,
ComponentCapabilities,
InternalComponentCapabilities,
} from '@glimmer/interfaces';
import { Attrs, AttrsDiff } from './emberish-glimmer';
import {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class EmberishCurlyComponentManager
return state.name;
}

getCapabilities(state: TestComponentDefinitionState): ComponentCapabilities {
getCapabilities(state: TestComponentDefinitionState): InternalComponentCapabilities {
return state.capabilities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
Option,
Bounds,
CapturedNamedArguments,
ComponentManager,
InternalComponentManager,
WithStaticLayout,
ComponentCapabilities,
InternalComponentCapabilities,
Environment,
VMArguments,
DynamicScope,
Expand Down Expand Up @@ -84,9 +84,9 @@ export interface EmberishGlimmerComponentState {

export class EmberishGlimmerComponentManager
implements
ComponentManager<EmberishGlimmerComponentState, TestComponentDefinitionState>,
InternalComponentManager<EmberishGlimmerComponentState, TestComponentDefinitionState>,
WithStaticLayout<EmberishGlimmerComponentState, TestComponentDefinitionState> {
getCapabilities(state: TestComponentDefinitionState): ComponentCapabilities {
getCapabilities(state: TestComponentDefinitionState): InternalComponentCapabilities {
return state.capabilities;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { WithStaticLayout, ComponentCapabilities, Template } from '@glimmer/interfaces';
import { WithStaticLayout, InternalComponentCapabilities, Template } from '@glimmer/interfaces';
import { TestComponentDefinitionState } from './test-component';
import { expect } from '@glimmer/util';
import { Reference, NULL_REFERENCE } from '@glimmer/reference';

export class TemplateOnlyComponentManager
implements WithStaticLayout<null, TestComponentDefinitionState> {
getCapabilities(state: TestComponentDefinitionState): ComponentCapabilities {
getCapabilities(state: TestComponentDefinitionState): InternalComponentCapabilities {
return state.capabilities;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentCapabilities, Template } from '@glimmer/interfaces';
import { InternalComponentCapabilities, Template } from '@glimmer/interfaces';

export interface TestComponentDefinitionState<T extends object = object> {
/* Manager-related */
capabilities: ComponentCapabilities;
capabilities: InternalComponentCapabilities;

/* Component-related */
name: string;
Expand Down
12 changes: 6 additions & 6 deletions packages/@glimmer/integration-tests/lib/modes/jit/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { TEMPLATE_ONLY_CAPABILITIES, CURLY_CAPABILITIES } from '../../components
import {
Option,
Helper as GlimmerHelper,
ModifierManager,
ComponentManager,
ComponentCapabilities,
InternalModifierManager,
InternalComponentManager,
InternalComponentCapabilities,
ComponentDefinition,
PartialDefinition,
TemplateFactory,
Expand Down Expand Up @@ -118,7 +118,7 @@ export function registerInternalHelper(
export function registerInternalModifier(
registry: TestJitRegistry,
name: string,
manager: ModifierManager<unknown, unknown>,
manager: InternalModifierManager<unknown, unknown>,
state: unknown
) {
registry.register('modifier', name, { manager, state });
Expand Down Expand Up @@ -193,10 +193,10 @@ export function registerComponent<K extends ComponentKind>(
function registerSomeComponent(
registry: TestJitRegistry,
name: string,
manager: ComponentManager<unknown, unknown>,
manager: InternalComponentManager<unknown, unknown>,
templateFactory: TemplateFactory | null,
ComponentClass: object,
capabilities: ComponentCapabilities
capabilities: InternalComponentCapabilities
) {
let state: TestComponentDefinitionState = {
name,
Expand Down
4 changes: 2 additions & 2 deletions packages/@glimmer/integration-tests/lib/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SimpleElement } from '@simple-dom/interface';
import {
Dict,
Option,
ModifierManager,
InternalModifierManager,
GlimmerTreeChanges,
Destroyable,
DynamicScope,
Expand All @@ -28,7 +28,7 @@ export class TestModifierDefinitionState {
}

export class TestModifierManager
implements ModifierManager<TestModifier, TestModifierDefinitionState> {
implements InternalModifierManager<TestModifier, TestModifierDefinitionState> {
create(
element: SimpleElement,
state: TestModifierDefinitionState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CapturedArguments,
CapturedRenderNode,
ComponentManager,
CustomRenderNode,
InternalComponentManager,
} from '@glimmer/interfaces';
import { expect, assign } from '@glimmer/util';
import { SimpleElement, SimpleNode } from '@simple-dom/interface';
Expand Down Expand Up @@ -50,7 +50,11 @@ interface ExpectedRenderNode {
}

class DebugRenderTreeDelegate extends JitRenderDelegate {
registerCustomComponent(name: string, template: string, Manager: { new (): ComponentManager }) {
registerCustomComponent(
name: string,
template: string,
Manager: { new (): InternalComponentManager<unknown> }
) {
const ComponentClass = templateOnlyComponent();

let state: TestComponentDefinitionState = {
Expand Down
3 changes: 1 addition & 2 deletions packages/@glimmer/interfaces/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './lib/compile';
export { default as ComponentCapabilities } from './lib/component-capabilities';
export * from './lib/components';
export * from './lib/components/component-manager';
export * from './lib/managers';
export * from './lib/content';
export * from './lib/core';
export * from './lib/dom/bounds';
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/interfaces/lib/compile/encoder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../template';
import { Op, MachineOp } from '../vm-opcodes';
import * as WireFormat from './wire-format';
import ComponentCapabilities from '../component-capabilities';
import { InternalComponentCapabilities } from '../managers/internal/component';

export interface Labels<InstructionEncoder> {
readonly labels: Dict<number>;
Expand Down Expand Up @@ -144,13 +144,13 @@ export interface IfResolvedComponentOp {
blocks: WireFormat.Core.Blocks;
staticTemplate: (
handle: number,
capabilities: ComponentCapabilities,
capabilities: InternalComponentCapabilities,
template: CompilableProgram,
blocks: IfResolvedComponentBlocks
) => StatementCompileActions;
dynamicTemplate: (
handle: number,
capabilities: ComponentCapabilities,
capabilities: InternalComponentCapabilities,
blocks: IfResolvedComponentBlocks
) => StatementCompileActions;
orElse?: () => ExpressionCompileActions;
Expand Down
88 changes: 0 additions & 88 deletions packages/@glimmer/interfaces/lib/component-capabilities.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/@glimmer/interfaces/lib/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line node/no-extraneous-import
import { Reference } from '@glimmer/reference';
import { ComponentManager } from './components/component-manager';
import { InternalComponentManager } from './managers';
import { Dict } from './core';

export type ComponentDefinitionState = unknown;
Expand All @@ -9,7 +9,7 @@ export type ComponentInstanceState = unknown;
export interface ComponentDefinition<
D = ComponentDefinitionState,
I = ComponentInstanceState,
M extends ComponentManager<I, D> = ComponentManager<I, D>
M extends InternalComponentManager<I, D> = InternalComponentManager<I, D>
> {
state: D;
manager: M;
Expand Down
Loading

0 comments on commit bff1273

Please sign in to comment.