@@ -29,24 +29,12 @@ external pushState: (Dom.history, @as(json`null`) _, @as("") _, ~href: string) =
2929external replaceState : (Dom .history , @as (json ` null` ) _ , @as ("" ) _ , ~href : string ) => unit =
3030 "replaceState"
3131
32- @val external event : 'a = "Event"
33-
34- @new external makeEventIE11Compatible : string => Dom .event = "Event"
35-
36- @val @scope ("document" )
37- external createEventNonIEBrowsers : string => Dom .event = "createEvent"
38-
39- @send
40- external initEventNonIEBrowsers : (Dom .event , string , bool , bool ) => unit = "initEvent"
41-
42- let safeMakeEvent = eventName =>
43- if typeof (event ) == #function {
44- makeEventIE11Compatible (eventName )
45- } else {
46- let event = createEventNonIEBrowsers ("Event" )
47- initEventNonIEBrowsers (event , eventName , true , true )
48- event
49- }
32+ type makeEventOptions = {
33+ bubbles ?: bool ,
34+ cancelable ?: bool ,
35+ composed ?: bool ,
36+ }
37+ @new external makeEvent : (string , ~options : makeEventOptions = ?) => Dom .event = "Event"
5038
5139/* This is copied from array.ml. We want to cut dependencies for rescript-react so
5240 that it's friendlier to use in size-constrained codebases */
@@ -129,7 +117,7 @@ let push = path =>
129117 | (_ , None ) => ()
130118 | (Some (history : Dom .history ), Some (window : Dom .window )) =>
131119 pushState (history , ~href = path )
132- dispatchEvent (window , safeMakeEvent ("popstate" ))
120+ dispatchEvent (window , makeEvent ("popstate" , ~ options = { bubbles : true , cancelable : true } ))
133121 }
134122
135123let replace = path =>
@@ -138,7 +126,7 @@ let replace = path =>
138126 | (_ , None ) => ()
139127 | (Some (history : Dom .history ), Some (window : Dom .window )) =>
140128 replaceState (history , ~href = path )
141- dispatchEvent (window , safeMakeEvent ("popstate" ))
129+ dispatchEvent (window , makeEvent ("popstate" , ~ options = { bubbles : true , cancelable : true } ))
142130 }
143131
144132type url = {
0 commit comments