Skip to content

Commit

Permalink
Removes ComponentRef from component implementation.
Browse files Browse the repository at this point in the history
This is no longer needed and isn't used for anything useful.
  • Loading branch information
dgp1130 committed Sep 7, 2024
1 parent a70122c commit 1e4e6bc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 49 deletions.
3 changes: 0 additions & 3 deletions src/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @fileoverview Defines symbols related to component definition. */

import { ComponentRef } from './component-ref.js';
import { HydroActiveComponent } from './hydroactive-component.js';
import { SignalComponentAccessor } from './signal-component-accessor.js';
import { ReactiveRoot } from './signals.js';
Expand All @@ -22,8 +21,6 @@ export function defineComponent(tagName: string, hydrate: HydrateLifecycle):
public override hydrate(): void {
const root = ReactiveRootImpl.from(this._connectable, this._scheduler);
const accessor = SignalComponentAccessor.fromSignalComponent(this, root);
const ref = ComponentRef._from(this._scheduler);
this._registerComponentRef(ref);
hydrate(accessor, root);
}
};
Expand Down
31 changes: 5 additions & 26 deletions src/hydroactive-component.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './testing/noop-component.js';

import { ComponentRef } from './component-ref.js';
import { HydroActiveComponent } from './hydroactive-component.js';
import { testCase, useTestCases } from './testing/test-cases.js';
import { TestScheduler } from './signals/schedulers/test-scheduler.js';
Expand All @@ -18,11 +17,7 @@ describe('hydroactive-component', () => {

describe('HydroActiveComponent', () => {
it('hydrates on upgrade when already connected to the DOM', testCase('already-rendered', () => {
const hydrate = jasmine.createSpy<Hydrate>('hydrate')
.and.callFake(function (this: HydroActiveComponent): void {
const ref = ComponentRef._from(TestScheduler.from());
this._registerComponentRef(ref);
});
const hydrate = jasmine.createSpy<Hydrate>('hydrate');

customElements.define(
'already-rendered',
Expand All @@ -35,11 +30,7 @@ describe('hydroactive-component', () => {
}));

it('hydrates on connect', () => {
const hydrate = jasmine.createSpy<Hydrate>('hydrate')
.and.callFake(function (this: HydroActiveComponent): void {
const ref = ComponentRef._from(TestScheduler.from());
this._registerComponentRef(ref);
});
const hydrate = jasmine.createSpy<Hydrate>('hydrate');

customElements.define(
'new-component',
Expand All @@ -57,11 +48,7 @@ describe('hydroactive-component', () => {
});

it('does not hydrate a second time when moved around the DOM', () => {
const hydrate = jasmine.createSpy<Hydrate>('hydrate')
.and.callFake(function (this: HydroActiveComponent): void {
const ref = ComponentRef._from(TestScheduler.from());
this._registerComponentRef(ref);
});
const hydrate = jasmine.createSpy<Hydrate>('hydrate');

customElements.define(
'another-component',
Expand All @@ -82,11 +69,7 @@ describe('hydroactive-component', () => {

describe('`defer-hydration`', () => {
it('defers hydration', testCase('deferred', (el) => {
const hydrate = jasmine.createSpy<Hydrate>('hydrate')
.and.callFake(function (this: HydroActiveComponent): void {
const ref = ComponentRef._from(TestScheduler.from());
this._registerComponentRef(ref);
});
const hydrate = jasmine.createSpy<Hydrate>('hydrate');

customElements.define(
'deferred-component',
Expand Down Expand Up @@ -133,11 +116,7 @@ describe('hydroactive-component', () => {
});

it('hydrates when `defer-hydration` is removed while disconnected from the DOM', testCase('disconnected-hydration', (el) => {
const hydrate = jasmine.createSpy<Hydrate>('hydrate')
.and.callFake(function (this: HydroActiveComponent): void {
const ref = ComponentRef._from(TestScheduler.from());
this._registerComponentRef(ref);
});
const hydrate = jasmine.createSpy<Hydrate>('hydrate');

customElements.define(
'disconnected-hydration',
Expand Down
12 changes: 0 additions & 12 deletions src/hydroactive-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ComponentRef } from './component-ref.js';
import { Connectable, Connector } from './connectable.js';
import { UiScheduler } from './signals/schedulers/ui-scheduler.js';

Expand Down Expand Up @@ -28,9 +27,6 @@ export abstract class HydroActiveComponent extends HTMLElement {
/** Whether or not the component has been hydrated. */
#hydrated = false;

/** The associated {@link ComponentRef} for this component. */
#ref?: ComponentRef;

protected _scheduler = UiScheduler.from();

constructor() {
Expand All @@ -47,12 +43,6 @@ export abstract class HydroActiveComponent extends HTMLElement {
/** User-defined lifecycle hook invoked on hydration. */
protected abstract hydrate(): void;

public /* internal */ _registerComponentRef(ref: ComponentRef): void {
if (this.#ref) throw new Error('Already registered a `ComponentRef`.');

this.#ref = ref;
}

connectedCallback(): void {
this.#connector.connect();

Expand Down Expand Up @@ -82,8 +72,6 @@ export abstract class HydroActiveComponent extends HTMLElement {

this.#hydrated = true;
this.hydrate();

if (!this.#ref) throw new Error('No registered `ComponentRef` after hydration.');
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/testing/noop-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ComponentRef } from '../component-ref.js';
import { ReactiveRoot } from '../signals.js';
import { ReactiveRootImpl } from '../signals/reactive-root.js';
import { HydroActiveComponent } from '../hydroactive-component.js';
Expand All @@ -10,7 +9,6 @@ import { SignalComponentAccessor } from '../signal-component-accessor.js';
* defining its own components and potentially conflicting tag names.
*/
export class NoopComponent extends HydroActiveComponent {
#ref!: ComponentRef;
#accessor!: SignalComponentAccessor<this>;

public readonly root: ReactiveRoot;
Expand All @@ -23,18 +21,12 @@ export class NoopComponent extends HydroActiveComponent {
this.root = ReactiveRootImpl.from(this._connectable, this._scheduler);
this.#accessor =
SignalComponentAccessor.fromSignalComponent(this, this.root);
this.#ref = ComponentRef._from(this._scheduler);
this._registerComponentRef(this.#ref);
}

protected override hydrate(): void {
this.hydrated = true;
}

public getComponentRef(): ComponentRef {
return this.#ref;
}

public getComponentAccessor(): SignalComponentAccessor<this> {
return this.#accessor;
}
Expand Down

0 comments on commit 1e4e6bc

Please sign in to comment.