Skip to content

Commit 051dce9

Browse files
committed
update examples
1 parent c5b43d6 commit 051dce9

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ examples/basic/basic.js.map
2626
examples/basic/basic.js
2727
examples/unwritableTime/unwritableTime.js
2828
examples/unwritableTime/unwritableTime.js.map
29+
examples/component/component.js
30+
examples/component/component.js.map

component.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func Extend(opt js.M) *Component {
6969
}
7070
}
7171

72-
func RegisterComponent(name string, component *Component) {
72+
func RegisterComponent(name string, component *Component) *Component {
7373
vue.Call("component", name, component.Object)
74+
return component
7475
}
7576

7677
func GetComponent(name string) *Component {

examples/basic/basic.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,49 @@ type Model struct {
3434
Now func() string `js:"Now"`
3535
}
3636

37-
func (m Model) Inc() {
37+
func (m *Model) Inc() {
3838
m.IntValue += 1
39+
println("inc called")
3940
}
4041

41-
func (m Model) Repeat() {
42+
func (m *Model) Repeat() {
4243
m.Str = strings.Repeat(m.Str, 3)
4344
}
4445

45-
func (m Model) PopulateTodo() {
46+
func (m *Model) PopulateTodo() {
4647
m.Todos = append(m.Todos, NewTodo(m.Str))
47-
vm := vue.Get(m)
48+
vm := vue.GetVM(m)
4849
println("Get(m):", vm)
4950
println("integer from vm:", vm.Get("integer").Int())
5051
}
5152

52-
func (m Model) Then() string {
53-
m.IntValue += 1
54-
return time.Now().String() + fmt.Sprintf(" ==> i:%d", m.IntValue)
53+
func (m *Model) WhatTF() string {
54+
println("then called", m.IntValue)
55+
// m.List = append(m.List, m.IntValue)
56+
return time.Now().String()
57+
}
58+
59+
func (m *Model) DoubleInt() int {
60+
return 2 * m.IntValue
5561
}
5662

5763
func main() {
5864
m := &Model{
59-
Object: js.Global.Get("Object").New(),
60-
IntValue: 100,
61-
List: []int{1, 2, 3, 4},
65+
Object: js.Global.Get("Object").New(),
6266
}
6367
// this is the correct way to initialize the gopherjs struct
6468
// which would be used in the JavaScript side.
65-
// m.IntValue = 100
69+
m.IntValue = 100
6670
m.Str = "a string"
6771
m.List = []int{1, 2, 3, 4}
6872
m.Todos = []*Todo{}
6973
m.AllItems = []string{"A", "B", "C", "D", "John", "Bill"}
7074
m.CheckedItems = []string{}
71-
m.Now = func() string { return time.Now().String() + fmt.Sprintf(" ==> i:%d", m.IntValue) }
75+
m.Now = func() string {
76+
println("now:", m.IntValue)
77+
return time.Now().String() + fmt.Sprintf(" ==> i:%d", m.IntValue)
78+
}
7279
v := vue.New("#app", m)
73-
println("vm:", v)
7480
v.WatchEx("integer", func(val *js.Object) {
7581
println("IntValue changed to:", val, "m.IntValue:", m.IntValue)
7682
m.Str = fmt.Sprintf("after watch:%d", m.IntValue)

examples/basic/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@
1414
<div id="app" v-cloak>
1515
integer: <span> {{ integer }} </span>
1616
<br>
17-
<div>Field Func: {{Now()}}</div>
18-
<div>Method Func: {{Then()}}</div>
17+
<div>Field Func: {{ Now() }}</div>
18+
<div>Methond Func: {{ WhatTF() }}</div>
19+
<div>DoubleInt: {{ DoubleInt() }}</div>
1920
<template v-for="item in AllItems">
2021
<label style="display: inline;">
2122
{{item}}
22-
<input type="checkbox" id="{{item}}" value="{{item}}" v-model="CheckedItems"></input>
23+
<input type="checkbox" id="{{item}}" value="{{item}}" v-model="CheckedItems" />
2324
</label>
2425
</template>
2526
<div>
2627
<span>CheckedItems: {{ CheckedItems | json }}</span>
2728
</div>
2829
<input v-model="integer">
29-
<button v-on:click="Inc">Inc</button>
30-
<button v-on:click="Repeat">Repeat</button>
31-
<button v-on:click="PopulateTodo">PopulateTodo</button>
30+
<button @click="Inc">Inc</button>
31+
<button @click="Repeat">Repeat</button>
32+
<button @click="PopulateTodo">PopulateTodo</button>
3233
<li v-for="item in list">
3334
{{ item }}
3435
</li>
35-
<input v-model="str"></input>
36+
<input v-model="str" />
3637
<ul v-for="todo in todos">
3738
<li>{{todo.time}} - {{todo.content}}</li>
3839
</ul>

examples/component/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Com struct {
1212

1313
func (c *Com) Hello() {
1414
println("hello" + c.Text)
15-
vm := vue.Get(c)
15+
vm := vue.GetVM(c)
1616
println("vm from Hello:", vm)
1717
println("vm.get:", vm.Get("text").String())
1818
}

0 commit comments

Comments
 (0)