Skip to content

Commit dbe1134

Browse files
committed
Refactor to use Angular for getting checkbox value.
Factor out []byte(scope.Get("code").String()) into a local variable. Rebuild playground.
1 parent dc5ff1a commit dbe1134

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

playground/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<input type="button" value="Run" ng-click="run(false)" />
1414
<input type="button" value="Format" ng-click="format()" />
1515
<label title="Rewrite imports on Format">
16-
<input id="imports" type="checkbox" checked />Imports
16+
<input ng-model="imports" type="checkbox" />Imports
1717
</label>
1818
<input type="button" value="Share" ng-click="share()" />
1919
<input type="text" class="show-share-url-{{showShareUrl}}" id="share-url" value="{{shareUrl}}" onfocus="select()" />

playground/playground.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func main() {
5656
scope.Set("code", "package main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/gopherjs/gopherjs/js\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hello, playground\")\n\tjs.Global.Call(\"alert\", \"Hello, JavaScript\")\n\tprintln(\"Hello, JS console\")\n}\n")
5757
close(codeReady)
5858
}
59+
scope.Set("imports", true)
5960
scope.Set("shareUrl", "")
6061
scope.Set("showShareUrl", false)
6162

@@ -202,13 +203,14 @@ func main() {
202203

203204
scope.Set("format", func() {
204205
go func() {
206+
code := []byte(scope.Get("code").String())
205207
var out []byte
206208
var err error
207-
switch dom.GetWindow().Document().GetElementByID("imports").(*dom.HTMLInputElement).Checked {
209+
switch scope.Get("imports").Bool() {
208210
case true:
209-
out, err = imports.Process("prog.go", []byte(scope.Get("code").String()), nil)
211+
out, err = imports.Process("prog.go", code, nil)
210212
case false:
211-
out, err = format.Source([]byte(scope.Get("code").String()))
213+
out, err = format.Source(code)
212214
}
213215
if err != nil {
214216
scope.Apply(func() {

playground/playground.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)