From 9e203aa7ee9eb12645c4520ac4baa21236c67e94 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 15 Feb 2020 20:47:24 +0100 Subject: Web: Move the Flow type cast function to its own module. Change-Id: I572c91e483fdb0a3b9fce4a9315b9dac92f9a31b --- .../resources/bookmarks/MlkBookmarkSubmissionForm.js | 19 +++++-------------- src/main/resources/META-INF/resources/types.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 src/main/resources/META-INF/resources/types.js (limited to 'src/main/resources/META-INF') diff --git a/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js index 41892c1..3d8c2e6 100644 --- a/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js +++ b/src/main/resources/META-INF/resources/bookmarks/MlkBookmarkSubmissionForm.js @@ -1,6 +1,7 @@ // @flow import ProgressSpinner from "../web_modules/elix/define/ProgressSpinner.js"; +import { cast } from "../types.js"; const template = document.createElement('template'); template.innerHTML = ` @@ -49,13 +50,13 @@ export class MlkBookmarkSubmissionForm extends HTMLElement { shadow.appendChild(template.content.cloneNode(true)); this.descriptionInput = - this.cast(shadow.getElementById('description-input')); + cast(shadow.getElementById('description-input')); this.titleInput = - this.cast(shadow.getElementById('title-input')); + cast(shadow.getElementById('title-input')); this.uriInput = - this.cast(shadow.getElementById('uri-input')); + cast(shadow.getElementById('uri-input')); this.uriSpinner = - this.cast(shadow.getElementById('uri-spinner')); + cast(shadow.getElementById('uri-spinner')); } static get observedAttributes() { @@ -116,16 +117,6 @@ export class MlkBookmarkSubmissionForm extends HTMLElement { let pageInfo = await r.json(); this.titleInput.value = pageInfo.title; } - - cast/*:: */(x /*: ?Object*/) /*: T*/ { - if (x === null || x === undefined) { - throw "unexpected null or undefined"; - } else { - /*:: (x: T); */ - return x; - } - } - } customElements.define("mlk-bookmark-submission-form", MlkBookmarkSubmissionForm); diff --git a/src/main/resources/META-INF/resources/types.js b/src/main/resources/META-INF/resources/types.js new file mode 100644 index 0000000..3ea0797 --- /dev/null +++ b/src/main/resources/META-INF/resources/types.js @@ -0,0 +1,10 @@ +// @flow + +export function cast/*:: */(x /*: ?Object*/) /*: T*/ { + if (x === null || x === undefined) { + throw "unexpected null or undefined"; + } else { + /*:: (x: T); */ + return x; + } +} -- cgit v1.2.3