1
+ @scope ("globalThis" )
2
+ external window : option <Dom .window > = "window"
3
+
4
+ @scope ("globalThis" )
5
+ external history : option <Dom .history > = "history"
6
+
1
7
@get external location : Dom .window => Dom .location = "location"
2
8
3
9
/* actually the cb is Dom.event => unit, but let's restrict the access for now */
@@ -81,13 +87,13 @@ let pathParse = str =>
81
87
raw |> Js .String .split ("/" ) |> Js .Array .filter (item => String .length (item ) != 0 ) |> arrayToList
82
88
}
83
89
let path = (~serverUrlString = ?, ()) =>
84
- switch (serverUrlString , % external ( window ) ) {
90
+ switch (serverUrlString , window ) {
85
91
| (None , None ) => list {}
86
92
| (Some (serverUrlString ), _ ) => pathParse (serverUrlString )
87
93
| (_ , Some (window : Dom .window )) => pathParse (window |> location |> pathname )
88
94
}
89
95
let hash = () =>
90
- switch % external ( window ) {
96
+ switch window {
91
97
| None => ""
92
98
| Some (window : Dom .window ) =>
93
99
switch window |> location |> hash {
@@ -111,14 +117,14 @@ let searchParse = str =>
111
117
}
112
118
113
119
let search = (~serverUrlString = ?, ()) =>
114
- switch (serverUrlString , % external ( window ) ) {
120
+ switch (serverUrlString , window ) {
115
121
| (None , None ) => ""
116
122
| (Some (serverUrlString ), _ ) => searchParse (serverUrlString )
117
123
| (_ , Some (window : Dom .window )) => searchParse (window |> location |> search )
118
124
}
119
125
120
126
let push = path =>
121
- switch (% external ( history ), % external ( window ) ) {
127
+ switch (history , window ) {
122
128
| (None , _ )
123
129
| (_ , None ) => ()
124
130
| (Some (history : Dom .history ), Some (window : Dom .window )) =>
@@ -127,7 +133,7 @@ let push = path =>
127
133
}
128
134
129
135
let replace = path =>
130
- switch (% external ( history ), % external ( window ) ) {
136
+ switch (history , window ) {
131
137
| (None , _ )
132
138
| (_ , None ) => ()
133
139
| (Some (history : Dom .history ), Some (window : Dom .window )) =>
@@ -169,7 +175,7 @@ let url = (~serverUrlString=?, ()) => {
169
175
let dangerouslyGetInitialUrl = url
170
176
171
177
let watchUrl = callback =>
172
- switch % external ( window ) {
178
+ switch window {
173
179
| None => () => ()
174
180
| Some (window : Dom .window ) =>
175
181
let watcherID = () => callback (url ())
@@ -178,7 +184,7 @@ let watchUrl = callback =>
178
184
}
179
185
180
186
let unwatchUrl = watcherID =>
181
- switch % external ( window ) {
187
+ switch window {
182
188
| None => ()
183
189
| Some (window : Dom .window ) => removeEventListener (window , "popstate" , watcherID )
184
190
}
0 commit comments