From 67a9c2e87f11f195f3caac357eac6296dd7b7374 Mon Sep 17 00:00:00 2001 From: Lukas Spirig Date: Tue, 12 Dec 2023 13:53:39 +0100 Subject: [PATCH] fix: review --- CODING_STANDARDS.md | 2 +- .../breadcrumb/breadcrumb-group/breadcrumb-group.ts | 2 +- src/components/checkbox/checkbox/checkbox.ts | 2 +- .../core/common-behaviors/language-controller.ts | 9 +-------- .../datepicker-next-day/datepicker-next-day.ts | 4 +--- .../datepicker-previous-day/datepicker-previous-day.ts | 4 +--- src/components/datepicker/datepicker/datepicker.ts | 2 +- .../form-field/form-field-clear/form-field-clear.ts | 2 +- src/components/form-field/form-field/form-field.ts | 2 +- .../navigation/navigation-action/navigation-action.ts | 2 +- src/components/navigation/navigation/navigation.ts | 2 +- src/components/radio-button/radio-button/radio-button.ts | 2 +- .../timetable-occupancy-icon/timetable-occupancy-icon.ts | 4 +--- src/components/toast/toast.ts | 2 +- src/components/train/train-formation/train-formation.ts | 2 +- 15 files changed, 15 insertions(+), 28 deletions(-) diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index bee87cf719..2a7c8df5c3 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -122,7 +122,7 @@ event and re-render the view. This can be done by marking the field with `@state import { LanguageController } from '../core/common-behaviors'; export class Component extends LitElement { - private _language = new LanguageController(this /*, this._abort */); + private _language = new LanguageController(this); protected override render(): TemplateResult { return html` ... ${i18nExample[this._language.current]} ... `; diff --git a/src/components/breadcrumb/breadcrumb-group/breadcrumb-group.ts b/src/components/breadcrumb/breadcrumb-group/breadcrumb-group.ts index 377f352bce..dc3b62d447 100644 --- a/src/components/breadcrumb/breadcrumb-group/breadcrumb-group.ts +++ b/src/components/breadcrumb/breadcrumb-group/breadcrumb-group.ts @@ -31,7 +31,7 @@ export class SbbBreadcrumbGroupElement extends SlotChildObserver(LitElement) { private _resizeObserver = new AgnosticResizeObserver(() => this._evaluateCollapsedState()); private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); private _markForFocus = false; private _handleKeyDown(evt: KeyboardEvent): void { diff --git a/src/components/checkbox/checkbox/checkbox.ts b/src/components/checkbox/checkbox/checkbox.ts index 6c10978944..51d5c7ce31 100644 --- a/src/components/checkbox/checkbox/checkbox.ts +++ b/src/components/checkbox/checkbox/checkbox.ts @@ -119,7 +119,7 @@ export class SbbCheckboxElement extends LitElement { private _checkbox: HTMLInputElement; private _selectionPanelElement: HTMLElement; private _abort: ConnectedAbortController = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); /** * @deprecated only used for React. Will probably be removed once React 19 is available. diff --git a/src/components/core/common-behaviors/language-controller.ts b/src/components/core/common-behaviors/language-controller.ts index 5673e08586..f06f79711b 100644 --- a/src/components/core/common-behaviors/language-controller.ts +++ b/src/components/core/common-behaviors/language-controller.ts @@ -2,7 +2,6 @@ import { ReactiveController, ReactiveControllerHost } from 'lit'; import { readConfig } from '../config'; import { isBrowser } from '../dom'; -import { ConnectedAbortController } from '../eventing'; import { AgnosticMutationObserver } from '../observers'; /** @@ -55,13 +54,7 @@ export class LanguageController implements ReactiveController { private _previousLanguage: string; private _handlers: (() => void)[] = []; - public constructor( - private _host: ReactiveControllerHost, - private _abortController?: ConnectedAbortController, - ) { - if (!this._abortController) { - this._abortController = new ConnectedAbortController(this._host); - } + public constructor(private _host: ReactiveControllerHost) { this._host.addController(this); } diff --git a/src/components/datepicker/datepicker-next-day/datepicker-next-day.ts b/src/components/datepicker/datepicker-next-day/datepicker-next-day.ts index 22e89d220e..524023801d 100644 --- a/src/components/datepicker/datepicker-next-day/datepicker-next-day.ts +++ b/src/components/datepicker/datepicker-next-day/datepicker-next-day.ts @@ -56,9 +56,7 @@ export class SbbDatepickerNextDayElement extends LitElement implements ButtonPro private _datePickerController: AbortController; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort).withHandler(() => - this._setAriaLabel(), - ); + private _language = new LanguageController(this).withHandler(() => this._setAriaLabel()); private _handleClick(): void { if (!this._datePickerElement || isValidAttribute(this, 'data-disabled')) { diff --git a/src/components/datepicker/datepicker-previous-day/datepicker-previous-day.ts b/src/components/datepicker/datepicker-previous-day/datepicker-previous-day.ts index 85fbbe446f..72dd480be5 100644 --- a/src/components/datepicker/datepicker-previous-day/datepicker-previous-day.ts +++ b/src/components/datepicker/datepicker-previous-day/datepicker-previous-day.ts @@ -56,9 +56,7 @@ export class SbbDatepickerPreviousDayElement extends LitElement implements Butto private _datePickerController: AbortController; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort).withHandler(() => - this._setAriaLabel(), - ); + private _language = new LanguageController(this).withHandler(() => this._setAriaLabel()); private _handleClick(): void { if (!this._datePickerElement || isValidAttribute(this, 'data-disabled')) { diff --git a/src/components/datepicker/datepicker/datepicker.ts b/src/components/datepicker/datepicker/datepicker.ts index e09ff62a52..6e46b46f25 100644 --- a/src/components/datepicker/datepicker/datepicker.ts +++ b/src/components/datepicker/datepicker/datepicker.ts @@ -327,7 +327,7 @@ export class SbbDatepickerElement extends LitElement { readConfig().datetime?.dateAdapter ?? defaultDateAdapter; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort).withHandler(() => { + private _language = new LanguageController(this).withHandler(() => { if (this._inputElement) { this._inputElement.placeholder = i18nDatePickerPlaceholder[this._language.current]; const valueAsDate = this.getValueAsDate(); diff --git a/src/components/form-field/form-field-clear/form-field-clear.ts b/src/components/form-field/form-field-clear/form-field-clear.ts index 9e0bcb235a..bfe33b41ef 100644 --- a/src/components/form-field/form-field-clear/form-field-clear.ts +++ b/src/components/form-field/form-field-clear/form-field-clear.ts @@ -28,7 +28,7 @@ export class SbbFormFieldClearElement extends LitElement { private _handlerRepository = new HandlerRepository(this, actionElementHandlerAspect); private _formField: SbbFormFieldElement; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); public override connectedCallback(): void { super.connectedCallback(); diff --git a/src/components/form-field/form-field/form-field.ts b/src/components/form-field/form-field/form-field.ts index 632b2e6c98..016545c1d5 100644 --- a/src/components/form-field/form-field/form-field.ts +++ b/src/components/form-field/form-field/form-field.ts @@ -118,7 +118,7 @@ export class SbbFormFieldElement extends LitElement { } private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); private _handlerRepository = new HandlerRepository( this, namedSlotChangeHandlerAspect((m) => (this._namedSlots = m(this._namedSlots))), diff --git a/src/components/navigation/navigation-action/navigation-action.ts b/src/components/navigation/navigation-action/navigation-action.ts index a833c28560..cc97a96072 100644 --- a/src/components/navigation/navigation-action/navigation-action.ts +++ b/src/components/navigation/navigation-action/navigation-action.ts @@ -89,7 +89,7 @@ export class SbbNavigationActionElement extends LitElement { private _navigationMarker: SbbNavigationMarkerElement; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); private _handlerRepository = new HandlerRepository(this, actionElementHandlerAspect); diff --git a/src/components/navigation/navigation/navigation.ts b/src/components/navigation/navigation/navigation.ts index c51fb4e3f0..5b5a49e6e0 100644 --- a/src/components/navigation/navigation/navigation.ts +++ b/src/components/navigation/navigation/navigation.ts @@ -120,7 +120,7 @@ export class SbbNavigationElement extends UpdateScheduler(LitElement) { private _navigationController: AbortController; private _windowEventsController: AbortController; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); private _focusTrap = new FocusTrap(); private _scrollHandler = new ScrollHandler(); private _isPointerDownEventOnNavigation: boolean; diff --git a/src/components/radio-button/radio-button/radio-button.ts b/src/components/radio-button/radio-button/radio-button.ts index 1d2bbe755a..629bf06238 100644 --- a/src/components/radio-button/radio-button/radio-button.ts +++ b/src/components/radio-button/radio-button/radio-button.ts @@ -126,7 +126,7 @@ export class SbbRadioButtonElement extends LitElement { private _selectionPanelElement: HTMLElement; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); /** * @internal diff --git a/src/components/timetable-occupancy-icon/timetable-occupancy-icon.ts b/src/components/timetable-occupancy-icon/timetable-occupancy-icon.ts index c75afc3fd0..9ca94df083 100644 --- a/src/components/timetable-occupancy-icon/timetable-occupancy-icon.ts +++ b/src/components/timetable-occupancy-icon/timetable-occupancy-icon.ts @@ -23,9 +23,7 @@ export class SbbTimetableOccupancyIconElement extends SbbIconBase { @property({ reflect: true, type: Boolean }) public negative: boolean = false; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort).withHandler(() => - this._setAriaLabel(), - ); + private _language = new LanguageController(this).withHandler(() => this._setAriaLabel()); private async _setNameAndAriaLabel(): Promise { if (!this.occupancy) { diff --git a/src/components/toast/toast.ts b/src/components/toast/toast.ts index 863d243660..681efc6fc6 100644 --- a/src/components/toast/toast.ts +++ b/src/components/toast/toast.ts @@ -117,7 +117,7 @@ export class SbbToastElement extends LitElement { private _closeTimeout: ReturnType; private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); /** * Role of the live region. This is only for Firefox as there is a known issue where Firefox + diff --git a/src/components/train/train-formation/train-formation.ts b/src/components/train/train-formation/train-formation.ts index a819263922..e5295a943f 100644 --- a/src/components/train/train-formation/train-formation.ts +++ b/src/components/train/train-formation/train-formation.ts @@ -39,7 +39,7 @@ export class SbbTrainFormationElement extends SlotChildObserver(LitElement) { private _formationDiv: HTMLDivElement; private _contentResizeObserver = new AgnosticResizeObserver(() => this._applyCssWidth()); private _abort = new ConnectedAbortController(this); - private _language = new LanguageController(this, this._abort); + private _language = new LanguageController(this); public override connectedCallback(): void { super.connectedCallback();