-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Accidentally using type-guards for HTMLLinkElement instead of HT…
…MLAnchorElement.
- Loading branch information
Showing
13 changed files
with
65 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export declare function isHTMLLinkElement(element: Element): element is HTMLLinkElement; | ||
export declare function isHTMLFormElement(element: Element): element is HTMLFormElement; | ||
export declare function isHTMLInputElement(element: Element): element is HTMLInputElement; | ||
export declare function isHTMLSelectElement(element: Element): element is HTMLSelectElement; | ||
export declare function isHTMLImageElement(element: Element): element is HTMLImageElement; | ||
export declare function isElementCheckable(element: Element): element is HTMLInputElement & { | ||
checked: boolean; | ||
}; | ||
export declare function isHTMLLinkElement(element: Element): element is HTMLLinkElement; | ||
export declare function isHTMLAnchorElement(element: Element): element is HTMLAnchorElement; | ||
export declare function isHTMLFormElement(element: Element): element is HTMLFormElement; | ||
export declare function isHTMLInputElement(element: Element): element is HTMLInputElement; | ||
export declare function isHTMLSelectElement(element: Element): element is HTMLSelectElement; | ||
export declare function isHTMLImageElement(element: Element): element is HTMLImageElement; | ||
export declare function isElementCheckable(element: Element): element is HTMLInputElement & { | ||
checked: boolean; | ||
}; | ||
//# sourceMappingURL=elements.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
import {BaseController} from './base_controller'; | ||
import {isHTMLFormElement, isHTMLLinkElement} from "./utilities/elements"; | ||
|
||
export class ConfirmController extends BaseController { | ||
|
||
static values = { | ||
message: String, | ||
}; | ||
|
||
declare readonly messageValue: string; | ||
declare readonly hasMessageValue: boolean; | ||
|
||
get message(): string { | ||
return this.hasMessageValue ? this.messageValue : 'Are you sure?'; | ||
} | ||
|
||
initialize() { | ||
this.confirm = this.confirm.bind(this); | ||
} | ||
|
||
connect() { | ||
requestAnimationFrame(() => { | ||
let element = this.el; | ||
if (isHTMLFormElement(element)) { | ||
element.addEventListener("submit", this.confirm); | ||
} else if (isHTMLLinkElement(element)) { | ||
element.addEventListener("click", this.confirm); | ||
} else { | ||
throw new Error("Can't handle confirmation on attached element"); | ||
} | ||
}); | ||
} | ||
|
||
confirm(event: Event) { | ||
if (!(window.confirm(this.message))) { | ||
event.preventDefault(); | ||
this.dispatch(this.el, "confirm:cancelled"); | ||
} | ||
} | ||
|
||
} | ||
import {BaseController} from './base_controller'; | ||
import {isHTMLFormElement, isHTMLAnchorElement} from "./utilities/elements"; | ||
|
||
export class ConfirmController extends BaseController { | ||
|
||
static values = { | ||
message: String, | ||
}; | ||
|
||
declare readonly messageValue: string; | ||
declare readonly hasMessageValue: boolean; | ||
|
||
get message(): string { | ||
return this.hasMessageValue ? this.messageValue : 'Are you sure?'; | ||
} | ||
|
||
initialize() { | ||
this.confirm = this.confirm.bind(this); | ||
} | ||
|
||
connect() { | ||
requestAnimationFrame(() => { | ||
let element = this.el; | ||
if (isHTMLFormElement(element)) { | ||
element.addEventListener("submit", this.confirm); | ||
} else if (isHTMLAnchorElement(element)) { | ||
element.addEventListener("click", this.confirm); | ||
} else { | ||
throw new Error("Can't handle confirmation on attached element"); | ||
} | ||
}); | ||
} | ||
|
||
confirm(event: Event) { | ||
if (!(window.confirm(this.message))) { | ||
event.preventDefault(); | ||
this.dispatch(this.el, "confirm:cancelled"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters