Add localstorage support

This commit is contained in:
Chris Sexton 2016-10-09 17:08:03 -04:00
parent 615e20c34a
commit e5357c54dc
2 changed files with 15 additions and 1 deletions

View File

@ -6,6 +6,7 @@ dependencies:
go get -u github.com/gopherjs/gopherjs go get -u github.com/gopherjs/gopherjs
go get -u github.com/bep/debounce go get -u github.com/bep/debounce
go get -u github.com/gopherjs/jquery go get -u github.com/gopherjs/jquery
go get -u go get github.com/go-humble/locstor
go get -u gitlab.com/chrissexton/togoist go get -u gitlab.com/chrissexton/togoist
togoist: togoist.go web.go dependencies togoist: togoist.go web.go dependencies

View File

@ -4,6 +4,7 @@ import (
"time" "time"
"github.com/bep/debounce" "github.com/bep/debounce"
"github.com/go-humble/locstor"
"github.com/gopherjs/jquery" "github.com/gopherjs/jquery"
"gitlab.com/chrissexton/togoist" "gitlab.com/chrissexton/togoist"
) )
@ -25,13 +26,25 @@ func handleChange() {
jQuery("#output").SetText(err.Error()) jQuery("#output").SetText(err.Error())
return return
} }
locstor.SetItem("tmpl", tmpl)
locstor.SetItem("input", input)
jQuery("#output").SetText(out) jQuery("#output").SetText(out)
}) })
} }
func getLocalStorage() {
if tmpl, err := locstor.GetItem("tmpl"); err == nil {
jQuery("#tmpl").SetText(tmpl)
}
if input, err := locstor.GetItem("input"); err == nil {
jQuery("#input").SetText(input)
}
handleChange()
}
func main() { func main() {
debounced, _ := debounce.New(time.Second) debounced, _ := debounce.New(time.Second)
jQuery("#tmpl").On(jquery.KEYUP, func() { debounced(handleChange) }) jQuery("#tmpl").On(jquery.KEYUP, func() { debounced(handleChange) })
jQuery("#input").On(jquery.KEYUP, func() { debounced(handleChange) }) jQuery("#input").On(jquery.KEYUP, func() { debounced(handleChange) })
handleChange() getLocalStorage()
} }