Skip to content

Commit

Permalink
make update hook an optional capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Apr 4, 2019
1 parent e4d7460 commit 3a8c092
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ const CAPABILITIES = {
export interface OptionalCapabilities {
asyncLifecycleCallbacks?: boolean;
destructor?: boolean;
updateHook?: boolean;
}

export function capabilities(managerAPI: '3.4', options: OptionalCapabilities = {}): Capabilities {
assert('Invalid component manager compatibility specified', managerAPI === '3.4');

let updateHook = true;

if (EMBER_CUSTOM_COMPONENT_ARG_PROXY) {
updateHook = updateHook: 'updateHook' in options ? Boolean(options.updateHook) : true;
}

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

Expand All @@ -66,6 +74,7 @@ export interface DefinitionState<ComponentInstance> {
export interface Capabilities {
asyncLifeCycleCallbacks: boolean;
destructor: boolean;
updateHook: boolean;
}

// TODO: export ICapturedArgumentsValue from glimmer and replace this
Expand Down Expand Up @@ -137,12 +146,12 @@ export interface ComponentArguments {
export default class CustomComponentManager<ComponentInstance>
extends AbstractComponentManager<
CustomComponentState<ComponentInstance>,
DefinitionState<ComponentInstance>
CustomComponentDefinitionState<ComponentInstance>
>
implements
WithStaticLayout<
CustomComponentState<ComponentInstance>,
DefinitionState<ComponentInstance>,
CustomComponentDefinitionState<ComponentInstance>,
OwnedTemplateMeta,
RuntimeResolver
> {
Expand Down Expand Up @@ -265,8 +274,12 @@ export default class CustomComponentManager<ComponentInstance>
}
}

getCapabilities(): ComponentCapabilities {
return CAPABILITIES;
getCapabilities({
delegate,
}: CustomComponentDefinitionState<ComponentInstance>): ComponentCapabilities {
return Object.assign({}, CAPABILITIES, {
updateHook: delegate.capabilities.updateHook,
});
}

getTag({ args }: CustomComponentState<ComponentInstance>): Tag {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { setOwner } from '@ember/-internals/owner';

class GlimmerishComponentManager {
constructor(owner) {
this.capabilities = capabilities('3.4');
this.capabilities = capabilities('3.4', { updateHook: false });
this.owner = owner;
}

createComponent(Factory, args) {
return new Factory(this.owner, args.named);
}

updateComponent() {}

getContext(component) {
return component;
}
Expand Down

0 comments on commit 3a8c092

Please sign in to comment.