Skip to content

Commit

Permalink
Remove listener after trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Jun 16, 2018
1 parent 694c9b0 commit e2618c2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions stores/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ func (s *CompileStore) compile() error {
// We need to wait for the iframe to load before adding contents or Firefox will clear the iframe
// after momentarily flashing up the contents.
c := make(chan struct{})
frame.AddEventListener("load", false, func(event dom.Event) {
listener := frame.AddEventListener("load", false, func(event dom.Event) {
close(c)
})

holder.AppendChild(frame)
<-c

// remove the listener so if it's triggered again we don't close the closed channel
frame.RemoveEventListener("load", false, listener)

console := dom.GetWindow().Document().GetElementByID("console")
console.SetInnerHTML("")
frame.Get("contentWindow").Set("goPrintToConsole", js.InternalObject(func(b []byte) {
Expand Down Expand Up @@ -142,13 +145,6 @@ func (s *CompileStore) compile() error {
frameDoc.Underlying().Call("open")
frameDoc.Underlying().Call("write", buf.String())
frameDoc.Underlying().Call("close")

// TODO: DON'T NEED THIS NOW? Confirm!
// c := make(chan struct{})
// frame.AddEventListener("load", false, func(event dom.Event) {
// close(c)
// })
// <-c
}

head := frameDoc.GetElementsByTagName("head")[0].(*dom.BasicHTMLElement)
Expand Down

0 comments on commit e2618c2

Please sign in to comment.