Web: Move the Flow type cast function to its own module.
Change-Id: I572c91e483fdb0a3b9fce4a9315b9dac92f9a31b
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 @@
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 @@
let pageInfo = await r.json();
this.titleInput.value = pageInfo.title;
}
-
- cast/*:: <T>*/(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/*:: <T>*/(x /*: ?Object*/) /*: T*/ {
+ if (x === null || x === undefined) {
+ throw "unexpected null or undefined";
+ } else {
+ /*:: (x: T); */
+ return x;
+ }
+}