Skip to content

Commit

Permalink
refactor: remove window.parent
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Aug 13, 2024
1 parent ada5a03 commit 6103680
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions src/Window.res
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,6 @@ module Location = {
external pathname: string = "pathname"
}

module Parent = {
module Location = {
@val @scope(("window", "parent", "location"))
external replace: string => unit = "replace"

@val @scope(("window", "parent", "location"))
external hostname: string = "hostname"

@val @scope(("window", "parent", "location"))
external href: string = "href"

@val @scope(("window", "parent", "location"))
external origin: string = "origin"

@val @scope(("window", "parent", "location"))
external protocol: string = "protocol"

@val @scope(("window", "parent", "location"))
external pathname: string = "pathname"
}
}

module Top = {
module Location = {
@val @scope(("window", "top", "location"))
Expand Down Expand Up @@ -216,30 +194,11 @@ let isIframed = () =>
}
}

let isParentAndTopSame = () =>
try {
Parent.Location.href === Top.Location.href
} catch {
| e => {
let default = false
Js.Console.error3(
"Failed to check whether or not parent and top were same",
e,
`Using "${default->String.make}" as default (due to DOMException)`,
)
default
}
}

let getRootHostName = () =>
switch isIframed() {
| true =>
try {
if isParentAndTopSame() {
Parent.Location.hostname
} else {
Top.Location.hostname
}
Top.Location.hostname
} catch {
| e => {
let default = Location.hostname
Expand All @@ -258,11 +217,7 @@ let replaceRootHref = (href: string) => {
switch isIframed() {
| true =>
try {
if isParentAndTopSame() {
Parent.Location.replace(href)
} else {
Top.Location.replace(href)
}
Top.Location.replace(href)
} catch {
| e => {
Js.Console.error3(
Expand Down

0 comments on commit 6103680

Please sign in to comment.