Skip to content

Commit

Permalink
perf(Controller): reduce object allocation needed for isConnected prop (
Browse files Browse the repository at this point in the history
microsoft#5160)

* perf(Controller): reduce object allocation needed for isConnected prop

* test(Controller): add notifier resolution test

* Change files

Co-authored-by: EisenbergEffect <roeisenb@microsoft.com>
  • Loading branch information
EisenbergEffect and EisenbergEffect authored Sep 8, 2021
1 parent 2581a5e commit bdd28c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf(Controller): reduce object allocation needed for isConnected prop",
"packageName": "@microsoft/fast-element",
"email": "roeisenb@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ describe("The Controller", () => {
}
});

it("should use itself as the notifier", () => {
const { controller } = createController();
const notifier = Observable.getNotifier(controller);
expect(notifier).to.equal(controller);
});

it("should have an observable isConnected property", () => {
const { element, controller } = createController();
let attached = controller.isConnected;
Expand Down
10 changes: 10 additions & 0 deletions packages/web-components/fast-element/src/components/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export class Controller extends PropertyChangeNotifier {
private _styles: ElementStyles | null = null;
private _isConnected: boolean = false;

/**
* This allows Observable.getNotifier(...) to return the Controller
* when the notifier for the Controller itself is being requested. The
* result is that the Observable system does not need to create a separate
* instance of Notifier for observables on the Controller. The component and
* the controller will now share the same notifier, removing one-object construct
* per web component instance.
*/
private readonly $fastController = this;

/**
* The element being controlled by this controller.
*/
Expand Down

0 comments on commit bdd28c8

Please sign in to comment.