Skip to content

Commit

Permalink
adding construction strategy to elementController
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasrice committed Oct 10, 2022
1 parent 88531e7 commit a115c0e
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { ElementViewTemplate } from "../templating/template.js";
import type { ElementView } from "../templating/view.js";
import { ElementStyles } from "../styles/element-styles.js";
import type { ViewController } from "../templating/html-directive.js";
import { FASTElementDefinition } from "./fast-definitions.js";
import { UnobservableMutationObserver } from "../utilities.js";
import { FASTElementDefinition } from "./fast-definitions.js";

const defaultEventOptions: CustomEventInit = {
bubbles: true,
Expand All @@ -24,6 +24,16 @@ function getShadowRoot(element: Element): ShadowRoot | null {
return element.shadowRoot ?? shadowRoots.get(element) ?? null;
}

export interface ElementControllerStrategy {
create(element: HTMLElement, definition: FASTElementDefinition): ElementController;
}

let elementControllerStrategy: ElementControllerStrategy = {
create(element, definition) {
return new ElementController(element, definition);
},
};

/**
* Controls the lifecycle and rendering of a `FASTElement`.
* @public
Expand Down Expand Up @@ -448,7 +458,7 @@ export class ElementController<TElement extends HTMLElement = HTMLElement>
throw FAST.error(Message.missingElementDefinition);
}

return ((element as any).$fastController = new ElementController(
return ((element as any).$fastController = elementControllerStrategy.create(
element,
definition
));
Expand Down Expand Up @@ -484,6 +494,14 @@ export class HydratableElementController<
}
}

export function addHydrationSupport() {
elementControllerStrategy = {
create(element, definition) {
return new HydratableElementController(element, definition);
},
};
}

/**
* Converts a styleTarget into the operative target. When the provided target is an Element
* that is a FASTElement, the function will return the ShadowRoot for that element. Otherwise,
Expand Down

0 comments on commit a115c0e

Please sign in to comment.