File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ package global
33import (
44 "encoding/base64"
55 "math/big"
6+ "strconv"
67
78 "github.com/qlova/script/language"
89 "github.com/qlova/seed/script"
10+ "github.com/qlova/seed/user"
911
1012 Javascript "github.com/qlova/script/language/javascript"
1113)
@@ -33,6 +35,11 @@ func (ref Reference) Set(q script.Ctx) {
3335 q .Javascript (`if (dynamic["` + ref .string + `"]) dynamic["` + ref .string + `"]();` )
3436}
3537
38+ //SetFor is a set method that should be called whenever the parent value is set.
39+ func (ref Reference ) SetFor (u user.Ctx ) {
40+ u .Execute (`if (dynamic["` + ref .string + `"]) dynamic["` + ref .string + `"]();` )
41+ }
42+
3643//New returns a new globl variable reference.
3744func New (name ... string ) Reference {
3845 if len (name ) > 0 {
@@ -70,6 +77,12 @@ func (s String) Set(q script.Ctx, value script.String) {
7077 s .Reference .Set (q )
7178}
7279
80+ //SetFor the global.String to be the given value.
81+ func (s String ) SetFor (u user.Ctx , value string ) {
82+ u .Execute (`window.localStorage.setItem("` + s .string + `", ` + strconv .Quote (value ) + `);` )
83+ s .Reference .SetFor (u )
84+ }
85+
7386//Bool is a global Boolean.
7487type Bool struct {
7588 Reference
You can’t perform that action at this time.
0 commit comments