Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 19da251

Browse files
committed
Support adding beforeunload event listener
tests and comment fix comment
1 parent b95d82f commit 19da251

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

lib/js/tests/Webapi/Webapi__Dom/Webapi__Dom__BeforeUnloadEvent__test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ $$event.stopPropagation();
3535

3636
$$event.returnValue;
3737

38+
$$event.returnValue = "Test";
39+
3840
exports.$$event = $$event;
3941
/* event Not a pure module */

lib/js/tests/Webapi/Webapi__Dom/Webapi__Dom__Window__test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ window.scrollBy(10.0, -10.0);
146146

147147
window.scrollTo(120.5, 300.3);
148148

149+
window.addEventListener("beforeunload", (function (param) {
150+
return /* () */0;
151+
}));
152+
153+
window.removeEventListener("beforeunload", (function (param) {
154+
return /* () */0;
155+
}));
156+
149157
window.stop();
150158

151159
window.onload = (function (param) {

src/Webapi/Webapi__Dom/Webapi__Dom__BeforeUnloadEvent.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ include Webapi__Dom__Event.Impl({ type nonrec t = t; });
66
[@bs.new] external makeWithOptions : (string, Js.t({..})) => t = "BeforeUnloadEvent";
77

88
[@bs.get] external returnValue : t => string = "";
9+
/**
10+
* returnValue cannot be unset because BS cannot (afaik) bind `delete e['returnValue'];`
11+
* Setting the value to undefined does not cause expected behavior.
12+
*/
13+
[@bs.set] external setReturnValue: (t, string) => unit = "returnValue";

src/Webapi/Webapi__Dom/Webapi__Dom__Window.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module Impl = (T: {type t;}) => {
9494

9595
[@bs.send.pipe : t_window] external addPopStateEventListener : ([@bs.as "popstate"] _, Dom.popStateEvent => unit) => unit = "addEventListener";
9696
[@bs.send.pipe : t_window] external removePopStateEventListener : ([@bs.as "popstate"] _, Dom.popStateEvent => unit) => unit= "removeEventListener";
97+
[@bs.send.pipe : t_window] external addBeforeUnloadEventListener : ([@bs.as "beforeunload"] _, Dom.beforeUnloadEvent => unit) => unit = "addEventListener";
98+
[@bs.send.pipe : t_window] external removeBeforeUnloadEventListener : ([@bs.as "beforeunload"] _, Dom.beforeUnloadEvent => unit) => unit= "removeEventListener";
9799

98100
[@bs.set] external setOnLoad : (t_window, unit => unit) => unit = "onload"; /* use addEventListener instead? */
99101
};

tests/Webapi/Webapi__Dom/Webapi__Dom__BeforeUnloadEvent__test.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ stopPropagation(event);
2121

2222
/* BeforeUnloadEvent */
2323
let _ = returnValue(event);
24+
setReturnValue(event, "Test");

tests/Webapi/Webapi__Dom/Webapi__Dom__Window__test.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ let _ = Window.resizeTo(120, 300, window);
7070
let _ = Window.scroll(0.0, 0.0, window);
7171
let _ = Window.scrollBy(10.0, (-10.0), window);
7272
let _ = Window.scrollTo(120.5, 300.3, window);
73+
Window.addBeforeUnloadEventListener((_: BeforeUnloadEvent.t) => (), window);
74+
Window.removeBeforeUnloadEventListener((_: BeforeUnloadEvent.t) => (), window);
7375
Window.stop(window);
7476
Window.setOnLoad(window, () => print_endline("load"));

0 commit comments

Comments
 (0)