-
Notifications
You must be signed in to change notification settings - Fork 570
Ability to change go vars (both JS primitives and JS Object) after they are #Set'ed to Js.Object #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The behavior that you see is fully expected for me. In case of var MyStringValue string
MyStringValue = "MyStringValue1"
js.Global.Set("MyStringValue", MyStringValue)
[...]
MyStringPointer := &MyStringValue
*MyStringPointer = "MyStringValue3"
println(js.Global.Get("MyStringValue")) it is essentially the same as var MyStringValue, GlobalMyStringValue string
MyStringValue = "MyStringValue1"
GlobalMyStringValue = MyStringValue
[...]
MyStringPointer := &MyStringValue
*MyStringPointer = "MyStringValue3"
println(GlobalMyStringValue) and you would not expect "MyStringValue3" here, right? In case of *MyStringPointer = "MyStringValue4"
js.Global.Set("MyStringValue", MyStringPointer)
println(js.Global.Get("MyStringValue")) it behaves according to http://godoc.org/github.com/gopherjs/gopherjs/js: What do you want to achieve? Maybe I can help you to find a good solution. |
For example, I am researching go-angular. package main
import (
"fmt"
"github.com/gopherjs/gopherjs/js"
)
func main() {
app.NewController("MyCtrl", func(scope *ng.Scope) {
myObject := &struct {
MyCompany string
MyName string
}{
"company1",
"name1",
}
scope.Set("myObject", myObject)
myObject.MyCompany = "company2"
scope.Set("myObject", myObject) // without which JS's myObject.MyCompany is still "company1"
// scope.$apply() //?
})
}
`` |
In other word, one of the most significant magics of AngularJS is "two-way binding" JS <-> DOM, thus it is important for Angular-Go to have "two-way biding" from Go <- ( <--> JS <--> ) -> DOM in order to be useful. |
Maybe you can use embedded |
Yes, package main
import (
"github.com/gopherjs/gopherjs/js"
)
type MyStruct1 struct {
js.Object
MyField1 string `js:"MyField1"`
}
func main() {
myStruct1 := MyStruct1{}
myStruct1.MyField1 = "MyField1Value2"
} I got
|
You have to set the |
Thanks, it works. Is there any trick to have fields with js tag directly in Go struct, instead of being in js.Object proxy? For example: type MyStruct1 struct {
o js.Object
MyField1 string `js:"MyField1"`
}
|
Only the type |
Yes, nested object is lengthy, like |
I'll try to come up with some better solution. |
(y) |
Have you had anything lead on this issue yet? |
I haven't forgotten this issue. I just have many things to do atm, sorry. I will take care of this at some point! :-) |
After reading the discussion in this issue, I tend to agree with #79 (comment). The original example seems to be working as intended and #236 appears to cover the literal initialization issue discussed later in the thread. I am going to close this issue now, but if you think this is a mistake — please let me know and we can reopen it. |
The text was updated successfully, but these errors were encountered: