1+ @scope ("globalThis" )
2+ external window : option <Dom .window > = "window"
3+
4+ @scope ("globalThis" )
5+ external history : option <Dom .history > = "history"
6+
17@get external location : Dom .window => Dom .location = "location"
28
39/* actually the cb is Dom.event => unit, but let's restrict the access for now */
@@ -81,13 +87,13 @@ let pathParse = str =>
8187 raw |> Js .String .split ("/" ) |> Js .Array .filter (item => String .length (item ) != 0 ) |> arrayToList
8288 }
8389let path = (~serverUrlString = ?, ()) =>
84- switch (serverUrlString , % external ( window ) ) {
90+ switch (serverUrlString , window ) {
8591 | (None , None ) => list {}
8692 | (Some (serverUrlString ), _ ) => pathParse (serverUrlString )
8793 | (_ , Some (window : Dom .window )) => pathParse (window |> location |> pathname )
8894 }
8995let hash = () =>
90- switch % external ( window ) {
96+ switch window {
9197 | None => ""
9298 | Some (window : Dom .window ) =>
9399 switch window |> location |> hash {
@@ -111,14 +117,14 @@ let searchParse = str =>
111117 }
112118
113119let search = (~serverUrlString = ?, ()) =>
114- switch (serverUrlString , % external ( window ) ) {
120+ switch (serverUrlString , window ) {
115121 | (None , None ) => ""
116122 | (Some (serverUrlString ), _ ) => searchParse (serverUrlString )
117123 | (_ , Some (window : Dom .window )) => searchParse (window |> location |> search )
118124 }
119125
120126let push = path =>
121- switch (% external ( history ), % external ( window ) ) {
127+ switch (history , window ) {
122128 | (None , _ )
123129 | (_ , None ) => ()
124130 | (Some (history : Dom .history ), Some (window : Dom .window )) =>
@@ -127,7 +133,7 @@ let push = path =>
127133 }
128134
129135let replace = path =>
130- switch (% external ( history ), % external ( window ) ) {
136+ switch (history , window ) {
131137 | (None , _ )
132138 | (_ , None ) => ()
133139 | (Some (history : Dom .history ), Some (window : Dom .window )) =>
@@ -169,7 +175,7 @@ let url = (~serverUrlString=?, ()) => {
169175let dangerouslyGetInitialUrl = url
170176
171177let watchUrl = callback =>
172- switch % external ( window ) {
178+ switch window {
173179 | None => () => ()
174180 | Some (window : Dom .window ) =>
175181 let watcherID = () => callback (url ())
@@ -178,7 +184,7 @@ let watchUrl = callback =>
178184 }
179185
180186let unwatchUrl = watcherID =>
181- switch % external ( window ) {
187+ switch window {
182188 | None => ()
183189 | Some (window : Dom .window ) => removeEventListener (window , "popstate" , watcherID )
184190 }
0 commit comments