Skip to content

Commit

Permalink
[FEAT] Upstream manager infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Nov 13, 2020
1 parent 97acdb5 commit 420fa9a
Show file tree
Hide file tree
Showing 28 changed files with 221 additions and 524 deletions.
5 changes: 2 additions & 3 deletions packages/@ember/-internals/glimmer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ export {
registerMacros as _registerMacros,
experimentalMacros as _experimentalMacros,
} from './lib/syntax';
export { default as AbstractComponentManager } from './lib/component-managers/abstract';

// needed for test
// TODO just test these through public API
Expand All @@ -400,8 +399,8 @@ export { default as AbstractComponentManager } from './lib/component-managers/ab
export { INVOKE } from './lib/helpers/action';
export { default as OutletView } from './lib/views/outlet';
export { OutletState } from './lib/utils/outlet';
export { setComponentManager, setModifierManager, setHelperManager } from './lib/utils/managers';
export { setComponentManager } from './lib/utils/managers';
export { capabilities } from './lib/component-managers/custom';
export { capabilities as modifierCapabilities } from './lib/modifiers/custom';
export { helperCapabilities, HelperManager, invokeHelper } from './lib/helpers/custom';
export { helperCapabilities, invokeHelper } from './lib/helpers/custom';
export { isSerializationFirstNode } from './lib/utils/serialization-first-node-helpers';
10 changes: 5 additions & 5 deletions packages/@ember/-internals/glimmer/lib/compile-time-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Owner } from '@ember/-internals/owner';
import {
CompileTimeComponent,
CompileTimeResolver,
ComponentCapabilities,
ComponentDefinition,
ComponentManager,
InternalComponentCapabilities,
InternalComponentManager,
Option,
WithStaticLayout,
} from '@glimmer/interfaces';
Expand All @@ -13,11 +13,11 @@ import RuntimeResolver from './resolver';

interface StaticComponentManager
extends WithStaticLayout<unknown, unknown>,
ComponentManager<unknown, unknown> {}
InternalComponentManager<unknown, unknown> {}

function isStaticComponentManager(
_manager: ComponentManager,
capabilities: ComponentCapabilities
_manager: InternalComponentManager,
capabilities: InternalComponentCapabilities
): _manager is StaticComponentManager {
return !capabilities.dynamicLayout;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { assign } from '@ember/polyfills';
import { DEBUG } from '@glimmer/env';
import {
Bounds,
ComponentCapabilities,
ComponentDefinition,
Destroyable,
ElementOperations,
Environment,
InternalComponentCapabilities,
Option,
PreparedArguments,
Template,
Expand All @@ -29,7 +29,7 @@ import {
Reference,
valueForRef,
} from '@glimmer/reference';
import { reifyPositional } from '@glimmer/runtime';
import { BaseInternalComponentManager, reifyPositional } from '@glimmer/runtime';
import { EMPTY_ARRAY } from '@glimmer/util';
import {
beginTrackFrame,
Expand All @@ -55,7 +55,6 @@ import {

import ComponentStateBucket, { Component } from '../utils/curly-component-state-bucket';
import { processComponentArgs } from '../utils/process-args';
import AbstractManager from './abstract';
import DefinitionState from './definition-state';

const EMBER_VIEW_REF = createPrimitiveRef('ember-view');
Expand Down Expand Up @@ -116,7 +115,7 @@ const EMPTY_POSITIONAL_ARGS: Reference[] = [];
debugFreeze(EMPTY_POSITIONAL_ARGS);

export default class CurlyComponentManager
extends AbstractManager<ComponentStateBucket, DefinitionState>
extends BaseInternalComponentManager<ComponentStateBucket, DefinitionState>
implements
WithDynamicLayout<ComponentStateBucket, RuntimeResolver>,
WithDynamicTagName<ComponentStateBucket> {
Expand Down Expand Up @@ -158,7 +157,7 @@ export default class CurlyComponentManager
return (component && component.tagName) || 'div';
}

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

Expand Down Expand Up @@ -575,7 +574,7 @@ interface CurriedArgs {
named: any;
}

export const CURLY_CAPABILITIES: ComponentCapabilities = {
export const CURLY_CAPABILITIES: InternalComponentCapabilities = {
dynamicLayout: true,
dynamicTag: true,
prepareArgs: true,
Expand Down
105 changes: 31 additions & 74 deletions packages/@ember/-internals/glimmer/lib/component-managers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ import { assert } from '@ember/debug';
import {
Arguments,
ComponentCapabilities,
ComponentCapabilitiesVersions,
ComponentDefinition,
ComponentManager,
ComponentManagerWithAsyncLifeCycleCallbacks,
ComponentManagerWithAsyncUpdateHook,
ComponentManagerWithDestructors,
ComponentManagerWithUpdateHook,
Destroyable,
Dict,
Environment,
InternalComponentCapabilities,
Option,
Template,
VMArguments,
WithStaticLayout,
} from '@glimmer/interfaces';
import { createConstRef, Reference } from '@glimmer/reference';
import { registerDestructor } from '@glimmer/runtime';
import {
BaseInternalComponentManager,
buildCapabilities,
registerDestructor,
} from '@glimmer/runtime';
import { argsProxyFor } from '../utils/args-proxy';
import { buildCapabilities, InternalCapabilities } from '../utils/managers';
import AbstractComponentManager from './abstract';

const CAPABILITIES = {
dynamicLayout: false,
Expand All @@ -33,29 +41,10 @@ const CAPABILITIES = {
willDestroy: false,
};

export interface OptionalCapabilities {
'3.4': {
asyncLifecycleCallbacks?: boolean;
destructor?: boolean;
};

'3.13': {
asyncLifecycleCallbacks?: boolean;
destructor?: boolean;
updateHook?: boolean;
};
}

export interface Capabilities extends InternalCapabilities {
asyncLifeCycleCallbacks: boolean;
destructor: boolean;
updateHook: boolean;
}

export function capabilities<Version extends keyof OptionalCapabilities>(
export function capabilities<Version extends keyof ComponentCapabilitiesVersions>(
managerAPI: Version,
options: OptionalCapabilities[Version] = {}
): Capabilities {
options: ComponentCapabilitiesVersions[Version] = {}
): ComponentCapabilities {
assert(
'Invalid component manager compatibility specified',
managerAPI === '3.4' || managerAPI === '3.13'
Expand All @@ -64,14 +53,14 @@ export function capabilities<Version extends keyof OptionalCapabilities>(
let updateHook = true;

if (managerAPI === '3.13') {
updateHook = Boolean((options as OptionalCapabilities['3.13']).updateHook);
updateHook = Boolean((options as ComponentCapabilitiesVersions['3.13']).updateHook);
}

return buildCapabilities({
asyncLifeCycleCallbacks: Boolean(options.asyncLifecycleCallbacks),
destructor: Boolean(options.destructor),
updateHook,
}) as Capabilities;
});
}

export interface DefinitionState<ComponentInstance> {
Expand All @@ -80,62 +69,30 @@ export interface DefinitionState<ComponentInstance> {
template: Template;
}

export interface ManagerDelegate<ComponentInstance> {
capabilities: Capabilities;
createComponent(factory: unknown, args: Arguments): ComponentInstance;
getContext(instance: ComponentInstance): unknown;
}

export function hasAsyncLifeCycleCallbacks<ComponentInstance>(
delegate: ManagerDelegate<ComponentInstance>
): delegate is ManagerDelegateWithAsyncLifeCycleCallbacks<ComponentInstance> {
delegate: ComponentManager<ComponentInstance>
): delegate is ComponentManagerWithAsyncLifeCycleCallbacks<ComponentInstance> {
return delegate.capabilities.asyncLifeCycleCallbacks;
}

export interface ManagerDelegateWithAsyncLifeCycleCallbacks<ComponentInstance>
extends ManagerDelegate<ComponentInstance> {
didCreateComponent(instance: ComponentInstance): void;
}

export function hasUpdateHook<ComponentInstance>(
delegate: ManagerDelegate<ComponentInstance>
): delegate is ManagerDelegateWithUpdateHook<ComponentInstance> {
delegate: ComponentManager<ComponentInstance>
): delegate is ComponentManagerWithUpdateHook<ComponentInstance> {
return delegate.capabilities.updateHook;
}

export interface ManagerDelegateWithUpdateHook<ComponentInstance>
extends ManagerDelegate<ComponentInstance> {
updateComponent(instance: ComponentInstance, args: Arguments): void;
}

export function hasAsyncUpdateHook<ComponentInstance>(
delegate: ManagerDelegate<ComponentInstance>
): delegate is ManagerDelegateWithAsyncUpdateHook<ComponentInstance> {
delegate: ComponentManager<ComponentInstance>
): delegate is ComponentManagerWithAsyncUpdateHook<ComponentInstance> {
return hasAsyncLifeCycleCallbacks(delegate) && hasUpdateHook(delegate);
}

export interface ManagerDelegateWithAsyncUpdateHook<ComponentInstance>
extends ManagerDelegateWithAsyncLifeCycleCallbacks<ComponentInstance>,
ManagerDelegateWithUpdateHook<ComponentInstance> {
didUpdateComponent(instance: ComponentInstance): void;
}

export function hasDestructors<ComponentInstance>(
delegate: ManagerDelegate<ComponentInstance>
): delegate is ManagerDelegateWithDestructors<ComponentInstance> {
delegate: ComponentManager<ComponentInstance>
): delegate is ComponentManagerWithDestructors<ComponentInstance> {
return delegate.capabilities.destructor;
}

export interface ManagerDelegateWithDestructors<ComponentInstance>
extends ManagerDelegate<ComponentInstance> {
destroyComponent(instance: ComponentInstance): void;
}

export interface ComponentArguments {
positional: unknown[];
named: Dict<unknown>;
}

/**
The CustomComponentManager allows addons to provide custom component
implementations that integrate seamlessly into Ember. This is accomplished
Expand All @@ -162,7 +119,7 @@ export interface ComponentArguments {
* `getContext()` - returns the object that should be
*/
export default class CustomComponentManager<ComponentInstance>
extends AbstractComponentManager<
extends BaseInternalComponentManager<
CustomComponentState<ComponentInstance>,
CustomComponentDefinitionState<ComponentInstance>
>
Expand All @@ -179,7 +136,7 @@ export default class CustomComponentManager<ComponentInstance>
let { delegate } = definition;
let args = argsProxyFor(vmArgs.capture(), 'component');

let component = delegate.createComponent(definition.ComponentClass.class, args);
let component = delegate.createComponent(definition.ComponentClass.class!, args);

let bucket = new CustomComponentState(delegate, component, args, env);

Expand Down Expand Up @@ -222,7 +179,7 @@ export default class CustomComponentManager<ComponentInstance>
return bucket;
}

getCapabilities(): ComponentCapabilities {
getCapabilities(): InternalComponentCapabilities {
return CAPABILITIES;
}

Expand All @@ -237,7 +194,7 @@ const CUSTOM_COMPONENT_MANAGER = new CustomComponentManager();
*/
export class CustomComponentState<ComponentInstance> {
constructor(
public delegate: ManagerDelegate<ComponentInstance>,
public delegate: ComponentManager<ComponentInstance>,
public component: ComponentInstance,
public args: Arguments,
public env: Environment
Expand All @@ -250,7 +207,7 @@ export class CustomComponentState<ComponentInstance> {

export interface CustomComponentDefinitionState<ComponentInstance>
extends DefinitionState<ComponentInstance> {
delegate: ManagerDelegate<ComponentInstance>;
delegate: ComponentManager<ComponentInstance>;
}

export class CustomManagerDefinition<ComponentInstance> implements ComponentDefinition {
Expand All @@ -262,7 +219,7 @@ export class CustomManagerDefinition<ComponentInstance> implements ComponentDefi
constructor(
public name: string,
public ComponentClass: Factory<ComponentInstance>,
public delegate: ManagerDelegate<ComponentInstance>,
public delegate: ComponentManager<ComponentInstance>,
public template: Template
) {
this.state = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Factory } from '@ember/-internals/owner';
import { ComponentCapabilities, Template } from '@glimmer/interfaces';
import { InternalComponentCapabilities, Template } from '@glimmer/interfaces';
import { Component } from '../utils/curly-component-state-bucket';

export default interface DefinitionState {
capabilities: ComponentCapabilities;
capabilities: InternalComponentCapabilities;
name: string;
ComponentClass: Factory<
Component,
Expand Down
Loading

0 comments on commit 420fa9a

Please sign in to comment.