You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2019/07/26 09:45:43 UTC

[myfaces-tobago] branch master updated: TOBAGO-1633: TS refactoring: casts now with 'as'

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new bfb9b71  TOBAGO-1633: TS refactoring: casts now with 'as'
bfb9b71 is described below

commit bfb9b71d62612b3fa0d375206affd7a4835d5109
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Jul 26 11:45:34 2019 +0200

    TOBAGO-1633: TS refactoring: casts now with 'as'
    
    * Instead of '<>' use 'as' for casting. This is the default since
      TypeScript 1.6.
---
 .../src/main/npm/ts/tobago-calendar.ts               | 10 +++++-----
 .../src/main/npm/ts/tobago-core.ts                   |  2 +-
 .../src/main/npm/ts/tobago-file.ts                   |  4 ++--
 .../src/main/npm/ts/tobago-focus.ts                  |  8 ++++----
 .../src/main/npm/ts/tobago-in.ts                     |  2 +-
 .../src/main/npm/ts/tobago-jsf.ts                    |  2 +-
 .../src/main/npm/ts/tobago-sheet.ts                  | 20 ++++++++++----------
 .../src/main/npm/ts/tobago-split-layout.ts           |  4 ++--
 .../src/main/npm/ts/tobago-tree-listbox.ts           | 18 +++++++++---------
 .../src/main/npm/ts/tobago-utils.ts                  | 16 ++++++++--------
 10 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
index 5fb4942..a02f9f7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
@@ -22,7 +22,7 @@ class DateTime {
 
   static init(element: HTMLElement) {
     for (const e of DomUtils.selfOrQuerySelectorAll(element, ".tobago-date:not([readonly]):not([disabled])")) {
-      const date: HTMLInputElement = <HTMLInputElement>e;
+      const date: HTMLInputElement = e as HTMLInputElement;
 
       const analyzed = DateTime.analyzePattern(date.dataset.tobagoPattern);
       const options = {
@@ -41,7 +41,7 @@ class DateTime {
         },
         keyBinds: {
           left: function ($widget) {
-            const widget: HTMLDivElement = <HTMLDivElement>$widget[0];
+            const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
             if (widget === undefined) {
               if (date.selectionStart === date.selectionEnd) {
                 if (date.selectionStart > 0 || date.selectionStart > 0) {
@@ -56,7 +56,7 @@ class DateTime {
             }
           },
           right: function ($widget) {
-            const widget: HTMLDivElement = <HTMLDivElement>$widget[0];
+            const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
             if (widget === undefined) {
               if (date.selectionStart === date.selectionEnd) {
                 if (date.selectionStart > 0 || date.selectionStart < date.value.length) {
@@ -71,7 +71,7 @@ class DateTime {
             }
           },
           enter: function ($widget) {
-            const widget: HTMLDivElement = <HTMLDivElement>$widget[0];
+            const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
             if (widget !== undefined && DomUtils.isVisible(widget.querySelector(".datepicker"))) {
               this.hide();
               fixKey(13);
@@ -84,7 +84,7 @@ class DateTime {
             }
           },
           escape: function ($widget) {
-            const widget: HTMLDivElement = <HTMLDivElement>$widget[0];
+            const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
             if (widget !== undefined && DomUtils.isVisible(widget.querySelector(".datepicker"))) {
               this.hide();
               fixKey(27);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
index 820d802..a1a235b 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
@@ -155,7 +155,7 @@ export class Tobago4 {
     Transport.request(function () {
       if (!Tobago4.isSubmit) {
         Tobago4.isSubmit = true;
-        const form = <HTMLFormElement>document.getElementsByTagName("form")[0];
+        const form = document.getElementsByTagName("form")[0] as HTMLFormElement;
         var oldTarget = form.getAttribute("target");
         var $sourceHidden = jQuery(DomUtils.escapeClientId("javax.faces.source"));
         $sourceHidden.prop("disabled", false);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
index 284277c..d5ec0c4 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
@@ -22,9 +22,9 @@ class File {
 
   static init(element: HTMLElement) {
     for (const e of DomUtils.selfOrQuerySelectorAll(element, ".tobago-file-real")) {
-      const real = <HTMLInputElement>e;
+      const real = e as HTMLInputElement;
       real.addEventListener("change", function () {
-        const pretty = <HTMLInputElement>real.parentElement.querySelector(".tobago-file-pretty");
+        const pretty = real.parentElement.querySelector(".tobago-file-pretty") as HTMLInputElement;
         let text: string;
         if (real.multiple) {
           const format: string = real.dataset["tobagoFileMultiFormat"];
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
index 9e4e075..b65585e 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
@@ -22,7 +22,7 @@ import {Listener, Phase} from "./tobago-listener";
 export class Focus {
 
   private static getHidden(): HTMLInputElement {
-    return <HTMLInputElement>document.getElementById(DomUtils.page().id + DomUtils.SUB_COMPONENT_SEP + "lastFocusId");
+    return document.getElementById(DomUtils.page().id + DomUtils.SUB_COMPONENT_SEP + "lastFocusId") as HTMLInputElement;
   }
 
   static setLastFocusId(id: string): void {
@@ -49,7 +49,7 @@ export class Focus {
 
     for (const focusable of activeInputs) {
       focusable.addEventListener("focus", function (event: FocusEvent) {
-        const target = <HTMLElement>event.target;
+        const target = event.target as HTMLElement;
         if (target.style.visibility !== "hidden" && target.style.display != "none") {
           // remember the last focused element, for later
           Focus.setLastFocusId(target.id);
@@ -108,8 +108,8 @@ export class Focus {
   }
 
   private static initAutoFocus(event) {
-    const modal = <HTMLElement>event.currentTarget;
-    (<HTMLElement>modal.querySelector("[autofocus]")).focus();
+    const modal = event.currentTarget as HTMLElement;
+    (modal.querySelector("[autofocus]") as HTMLElement).focus();
   }
 }
 
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
index 8b2e46e..446aeaa 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
@@ -26,7 +26,7 @@ class RegExpTest {
 
   static init(element: HTMLElement): void {
     for (const input of DomUtils.selfOrElementsByClassName(element, "tobago-in")) { // todo only for data-regexp
-      new RegExpTest(<HTMLInputElement>input);
+      new RegExpTest(input as HTMLInputElement);
     }
   }
 
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
index 71c6a61..1eb6b25 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
@@ -75,7 +75,7 @@ class Jsf {
             } else if (Jsf.isBody(id)) {
               console.debug("[tobago-jsf] updating body");
               // there should be only one element with this class
-              Listener.executeAfterUpdate(document.querySelector<HTMLElement>(".tobago-page"));
+              Listener.executeAfterUpdate(document.querySelector(".tobago-page") as HTMLElement);
             }
           }
         });
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
index a1ec4fe..576caa4 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
@@ -262,7 +262,7 @@ class Sheet {
     // begin resizing
     console.debug("down");
 
-    const resizeElement = <HTMLElement>event.currentTarget;
+    const resizeElement = event.currentTarget as HTMLElement;
     const columnIndex = parseInt(resizeElement.dataset["tobagoColumnIndex"]);
     const headerColumn = this.getHeaderCols().item(columnIndex);
     const mousemoveListener = this.mousemove.bind(this);
@@ -365,7 +365,7 @@ class Sheet {
   }
 
   clickOnCheckbox(event: MouseEvent) {
-    const checkbox = <HTMLInputElement>event.currentTarget;
+    const checkbox = event.currentTarget as HTMLInputElement;
     if (checkbox.checked) {
       this.selectAll();
     } else {
@@ -375,7 +375,7 @@ class Sheet {
 
   clickOnRow(event: MouseEvent) {
 
-    const row = <HTMLTableRowElement>event.currentTarget;
+    const row = event.currentTarget as HTMLTableRowElement;
     if (row.classList.contains("tobago-sheet-columnSelector") || !Sheet.isInputElement(row)) {
       const sheet = this.getElement();
 
@@ -443,20 +443,20 @@ class Sheet {
   }
 
   clickOnPaging(event: MouseEvent) {
-    const element = <HTMLElement>event.currentTarget;
+    const element = event.currentTarget as HTMLElement;
 
-    const output = <HTMLElement>element.querySelector(".tobago-sheet-pagingOutput");
+    const output = element.querySelector(".tobago-sheet-pagingOutput") as HTMLElement;
     output.style.display = "none";
 
-    const input = <HTMLInputElement>element.querySelector(".tobago-sheet-pagingInput");
+    const input = element.querySelector(".tobago-sheet-pagingInput") as HTMLInputElement;
     input.style.display = "initial";
     input.focus();
     input.select();
   }
 
   blurPaging(event: FocusEvent) {
-    const input = <HTMLInputElement>event.currentTarget;
-    const output = <HTMLElement>input.parentElement.querySelector(".tobago-sheet-pagingOutput");
+    const input = event.currentTarget as HTMLInputElement;
+    const output = input.parentElement.querySelector(".tobago-sheet-pagingOutput") as HTMLElement;
     if (output.innerHTML !== input.value) {
       console.debug("Reloading sheet '" + this.id + "' old value='" + output.innerHTML + "' new value='" + input.value + "'");
       output.innerHTML = input.value;
@@ -508,7 +508,7 @@ class Sheet {
   }
 
   getHiddenSelected(): HTMLInputElement {
-    return <HTMLInputElement>document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected");
+    return document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected") as HTMLInputElement;
   }
 
   getHiddenScrollPosition() {
@@ -516,7 +516,7 @@ class Sheet {
   }
 
   doDblClick(event) {
-    const row = <HTMLTableRowElement>event.currentTarget;
+    const row = event.currentTarget as HTMLTableRowElement;
     const rowIndex = row.sectionRowIndex + this.getFirst();
     if (this.dblClickActionId) {
       let action;
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
index 5124a61..93bcef2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
@@ -26,7 +26,7 @@ class SplitLayout {
 
   static init = function (element: HTMLElement): void {
     for (const splitLayout of DomUtils.selfOrElementsByClassName(element, "tobago-splitLayout")) {
-      new SplitLayout(<HTMLDivElement>splitLayout);
+      new SplitLayout(splitLayout as HTMLDivElement);
     }
   };
 
@@ -48,7 +48,7 @@ class SplitLayout {
 
   start(event: MouseEvent) {
     event.preventDefault();
-    const splitter = <HTMLElement>event.target;
+    const splitter = event.target as HTMLElement;
     const previous = DomUtils.previousElementSibling(splitter);
     this.offset = this.horizontal ? event.pageX - previous.offsetWidth : event.pageY - previous.offsetHeight;
     const mousedown = SplitLayoutMousedown.save(event, splitter);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
index 8026b54..8d0e04a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
@@ -34,7 +34,7 @@ class TreeListbox {
 
     const selects = element.getElementsByTagName("select");
     for (let i = 0; i < selects.length; i++) {
-      const listbox = <HTMLSelectElement>selects.item(i);
+      const listbox = selects.item(i) as HTMLSelectElement;
       // hide select tags for level > root
       if (listbox.previousElementSibling) {
         listbox.classList.add("d-none");
@@ -49,22 +49,22 @@ class TreeListbox {
   }
 
   onChange(event: TextEvent) {
-    let listbox = <HTMLSelectElement>event.currentTarget;
+    let listbox = event.currentTarget as HTMLSelectElement;
     for (const child of listbox.children) {
-      const option = <HTMLOptionElement>child;
+      const option = child as HTMLOptionElement;
       if (option.tagName === "OPTION") {
         if (option.selected) {
           this.setSelected(option);
-          let select = <HTMLSelectElement>document.getElementById(option.id + DomUtils.SUB_COMPONENT_SEP + "parent");
+          let select = document.getElementById(option.id + DomUtils.SUB_COMPONENT_SEP + "parent") as HTMLSelectElement;
           if (!select) {
-            select = <HTMLSelectElement>listbox.parentElement.nextElementSibling.children[0]; // dummy
+            select = listbox.parentElement.nextElementSibling.children[0] as HTMLSelectElement; // dummy
           }
           select.classList.remove("d-none");
           for (const sibling of listbox.parentElement.nextElementSibling.children) {
             if (sibling === select) {
-              (<HTMLElement>sibling).classList.remove("d-none");
+              (sibling as HTMLElement).classList.remove("d-none");
             } else {
-              (<HTMLElement>sibling).classList.add("d-none");
+              (sibling as HTMLElement).classList.add("d-none");
             }
           }
         }
@@ -78,7 +78,7 @@ class TreeListbox {
     if (next) {
       for (next = next.nextElementSibling; next; next = next.nextElementSibling) {
         for (const child of next.children) {
-          const select = <HTMLSelectElement>child;
+          const select = child as HTMLSelectElement;
           if (select.previousElementSibling) { // is not the first
             select.classList.add("d-none");
           } else { // is the first
@@ -90,7 +90,7 @@ class TreeListbox {
   }
 
   setSelected(option: HTMLOptionElement) {
-    const hidden = <HTMLInputElement>document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected");
+    const hidden = document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected") as HTMLInputElement;
     if (hidden) {
       let value = <number[]>JSON.parse(hidden.value);
       value = []; // todo: multi-select
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
index db7de6c..379f217 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
@@ -36,7 +36,7 @@ export class DomUtils {
       if (pages.length >= 2) {
         console.warn("Found more than one tobago page!");
       }
-      return <HTMLElement>pages.item(0);
+      return pages.item(0) as HTMLElement;
     }
     console.warn("Found no tobago page!");
     return null;
@@ -54,7 +54,7 @@ export class DomUtils {
     }
     const list = element.getElementsByClassName(className);
     for (let i = 0; i < list.length; i++) {
-      result.push(<HTMLElement>list.item(i));
+      result.push(list.item(i) as HTMLElement);
     }
     return result;
   }
@@ -71,7 +71,7 @@ export class DomUtils {
       result.push(element);
     }
     for (const found of element.querySelectorAll(selectors)) {
-      result.push(<HTMLElement>found);
+      result.push(found as HTMLElement);
     }
     return result;
   }
@@ -86,7 +86,7 @@ export class DomUtils {
     const result: Array<HTMLElement> = new Array<HTMLElement>();
     for (const child of element.children) {
       if (child.matches(selectors)) {
-        result.push(<HTMLElement>child);
+        result.push(child as HTMLElement);
       }
     }
     return result;
@@ -111,12 +111,12 @@ export class DomUtils {
    * Get the previous sibling element (without <style> elements).
    */
   static previousElementSibling(element: HTMLElement): HTMLElement {
-    let sibling = <HTMLElement>element.previousElementSibling;
+    let sibling = element.previousElementSibling as HTMLElement;
     while (sibling != null) {
       if (sibling.tagName !== "STYLE") {
         return sibling;
       }
-      sibling = <HTMLElement>sibling.previousElementSibling;
+      sibling = sibling.previousElementSibling as HTMLElement;
     }
     return null;
   }
@@ -125,12 +125,12 @@ export class DomUtils {
    * Get the next sibling element (without <style> elements).
    */
   static nextElementSibling(element: HTMLElement): HTMLElement {
-    let sibling = <HTMLElement>element.nextElementSibling;
+    let sibling = element.nextElementSibling as HTMLElement;
     while (sibling !== null) {
       if (sibling.tagName !== "STYLE") {
         return sibling;
       }
-      sibling = <HTMLElement>sibling.nextElementSibling;
+      sibling = sibling.nextElementSibling as HTMLElement;
     }
     return null;
   }