Skip to content

ROU-11926: Protecting code that is run async #1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OSFramework.OSUI.Patterns.AnimatedLabel {
private _eventBlur: GlobalCallbacks.Generic;
private _eventFocus: GlobalCallbacks.Generic;
private _eventKeyDown: GlobalCallbacks.Generic;
private _isDisposed = false;

// Set the input html element
private _inputElement: HTMLInputElement | HTMLTextAreaElement;
Expand Down Expand Up @@ -101,11 +102,13 @@ namespace OSFramework.OSUI.Patterns.AnimatedLabel {

// Method to remove Pattern Events
private _removeEvents(): void {
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.Blur, this._eventBlur);
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.Focus, this._eventFocus);
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.AnimationStart, this._eventAnimationStart);
if (this._inputElement.type === 'number') {
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.keyDown, this._eventKeyDown);
if (this._inputElement) {
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.Blur, this._eventBlur);
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.Focus, this._eventFocus);
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.AnimationStart, this._eventAnimationStart);
if (this._inputElement.type === 'number') {
this._inputElement.removeEventListener(GlobalEnum.HTMLEvent.keyDown, this._eventKeyDown);
}
}
}

Expand Down Expand Up @@ -196,13 +199,16 @@ namespace OSFramework.OSUI.Patterns.AnimatedLabel {
public build(): void {
//OS takes a while to set the TextArea
Helper.AsyncInvocation(() => {
super.build();
if (!this._isDisposed) {
// Set the common html elements
super.build();

this.setHtmlElements();
this.setHtmlElements();

this.setCallbacks();
this.setCallbacks();

this.finishBuild();
this.finishBuild();
}
});
}

Expand All @@ -212,6 +218,7 @@ namespace OSFramework.OSUI.Patterns.AnimatedLabel {
* @memberof OSFramework.Patterns.AnimatedLabel.AnimatedLabel
*/
public dispose(): void {
this._isDisposed = true;
this.unsetCallbacks();

this.unsetHtmlElements();
Expand Down
32 changes: 17 additions & 15 deletions src/scripts/OSFramework/OSUI/Pattern/Notification/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,27 @@ namespace OSFramework.OSUI.Patterns.Notification {
* @memberof OSFramework.Patterns.Notification.Notification
*/
protected setInitialStates(): void {
// Set event if device is touch
if (Helper.DeviceInfo.IsTouch) {
this._eventType = GlobalEnum.HTMLEvent.TouchStart;
} else {
this._eventType = GlobalEnum.HTMLEvent.Click;
}
if (this.isBuilt) {
// Set event if device is touch
if (Helper.DeviceInfo.IsTouch) {
this._eventType = GlobalEnum.HTMLEvent.TouchStart;
} else {
this._eventType = GlobalEnum.HTMLEvent.Click;
}

// Set width value for Notification
Helper.Dom.Styles.SetStyleAttribute(this.selfElement, Enum.CssProperty.Width, this.configs.Width);
// Set width value for Notification
Helper.Dom.Styles.SetStyleAttribute(this.selfElement, Enum.CssProperty.Width, this.configs.Width);

// Set position initial class
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClass.PatternPosition + this.configs.Position);
// Set position initial class
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClass.PatternPosition + this.configs.Position);

if (this._isOpen) {
this._showNotification();
}
if (this._isOpen) {
this._showNotification();
}

if (this.configs.CloseAfterTime > 0 && this._isOpen) {
this._autoCloseNotification();
if (this.configs.CloseAfterTime > 0 && this._isOpen) {
this._autoCloseNotification();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ namespace OSFramework.OSUI.Patterns.Progress.Bar {
* @memberof OSFramework.Patterns.Progress.Bar.Bar
*/
protected addInitialAnimation(): void {
// Check if the animation at init should be added
if (this.configs.AnimateInitialProgress) {
this.animateInitial();
if (this.isBuilt) {
// Check if the animation at init should be added
if (this.configs.AnimateInitialProgress) {
this.animateInitial();
}

// Update the progress value and the valuenow accessibility property
this.updatedProgressValue();
}

// Update the progress value and the valuenow accessibility property
this.updatedProgressValue();
}

/**
Expand Down
90 changes: 51 additions & 39 deletions src/scripts/OSFramework/OSUI/Pattern/Tabs/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ namespace OSFramework.OSUI.Patterns.Tabs {
}
}

// Update scale size variable
Helper.AsyncInvocation(this._handleTabIndicator.bind(this));
// Update scale size variable
Helper.AsyncInvocation(this._handleTabIndicator.bind(this));
}
}

Expand All @@ -523,16 +523,18 @@ namespace OSFramework.OSUI.Patterns.Tabs {

// Method to set if the Tabs AutoHeight
private _setContentAutoHeight(hasAutoHeight: boolean): void {
if (this._hasDragGestures === false) {
if (hasAutoHeight) {
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.HasContentAutoHeight);
if (this.isBuilt) {
if (this._hasDragGestures === false) {
if (hasAutoHeight) {
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.HasContentAutoHeight);
} else {
Helper.Dom.Styles.RemoveClass(this.selfElement, Enum.CssClasses.HasContentAutoHeight);
}
} else {
Helper.Dom.Styles.RemoveClass(this.selfElement, Enum.CssClasses.HasContentAutoHeight);
console.warn(
`Tabs (${this.widgetId}): changes to ${Enum.Properties.ContentAutoHeight} parameter do not affect tabs when Gestures are in use.`
);
}
} else {
console.warn(
`Tabs (${this.widgetId}): changes to ${Enum.Properties.ContentAutoHeight} parameter do not affect tabs when Gestures are in use.`
);
}
}

Expand Down Expand Up @@ -575,19 +577,21 @@ namespace OSFramework.OSUI.Patterns.Tabs {

// Method to set the Tabs Height
private _setHeight(height: string): void {
// Set tabs overflow based on height
const tabsOverflow =
height === GlobalEnum.CssProperties.Auto || height === Constants.EmptyString
? GlobalEnum.CssProperties.Initial
: GlobalEnum.CssProperties.Auto;

// Create css variables
Helper.Dom.Styles.SetStyleAttribute(this.selfElement, Enum.CssProperty.TabsHeight, height);
Helper.Dom.Styles.SetStyleAttribute(
this.selfElement,
Enum.CssProperty.TabsContentItemOverflow,
tabsOverflow
);
if (this.isBuilt) {
// Set tabs overflow based on height
const tabsOverflow =
height === GlobalEnum.CssProperties.Auto || height === Constants.EmptyString
? GlobalEnum.CssProperties.Initial
: GlobalEnum.CssProperties.Auto;

// Create css variables
Helper.Dom.Styles.SetStyleAttribute(this.selfElement, Enum.CssProperty.TabsHeight, height);
Helper.Dom.Styles.SetStyleAttribute(
this.selfElement,
Enum.CssProperty.TabsContentItemOverflow,
tabsOverflow
);
}
}

// Method to set the initial options on screen load
Expand All @@ -610,13 +614,12 @@ namespace OSFramework.OSUI.Patterns.Tabs {

// Method to set if the Tabs are justified
private _setIsJustified(isJustified: boolean): void {
if (isJustified) {
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.IsJustified);
} else {
Helper.Dom.Styles.RemoveClass(this.selfElement, Enum.CssClasses.IsJustified);
}

if (this.isBuilt) {
if (isJustified) {
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.IsJustified);
} else {
Helper.Dom.Styles.RemoveClass(this.selfElement, Enum.CssClasses.IsJustified);
}
// Update scale size variable
this._handleTabIndicator();
}
Expand All @@ -638,10 +641,15 @@ namespace OSFramework.OSUI.Patterns.Tabs {

// Method to set the Tabs Position
private _setPosition(position: GlobalEnum.Direction): void {
Helper.Dom.Styles.RemoveClass(this.selfElement, Enum.CssClasses.Modifier + this._currentVerticalPositon);
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.Modifier + position);
if (this.isBuilt) {
Helper.Dom.Styles.RemoveClass(
this.selfElement,
Enum.CssClasses.Modifier + this._currentVerticalPositon
);
Helper.Dom.Styles.AddClass(this.selfElement, Enum.CssClasses.Modifier + position);

this._currentVerticalPositon = position;
this._currentVerticalPositon = position;
}
}

// Toggles the TableHeaderItem disabled status
Expand Down Expand Up @@ -770,10 +778,12 @@ namespace OSFramework.OSUI.Patterns.Tabs {
* @memberof OSFramework.Patterns.Tabs.Tabs
*/
protected setA11YProperties(): void {
// Set aria-role to TabsHeader
Helper.A11Y.RoleTabList(this._tabsHeaderElement.firstElementChild as HTMLElement);
// Set aria-hidden to tabs indicator
Helper.A11Y.AriaHiddenTrue(this._tabsIndicatorElement);
if (this.isBuilt) {
// Set aria-role to TabsHeader
Helper.A11Y.RoleTabList(this._tabsHeaderElement.firstElementChild as HTMLElement);
// Set aria-hidden to tabs indicator
Helper.A11Y.AriaHiddenTrue(this._tabsIndicatorElement);
}
}

/**
Expand All @@ -783,9 +793,11 @@ namespace OSFramework.OSUI.Patterns.Tabs {
* @memberof OSFramework.Patterns.Tabs.Tabs
*/
protected setCallbacks(): void {
this._eventOnHeaderKeypress = this._handleKeypressEvent.bind(this);
this._eventOnResize = this._handleOnResizeEvent.bind(this);
this._addEvents();
if (this.isBuilt) {
this._eventOnHeaderKeypress = this._handleKeypressEvent.bind(this);
this._eventOnResize = this._handleOnResizeEvent.bind(this);
this._addEvents();
}
}

/**
Expand Down
Loading