Skip to content

Commit c01ba7c

Browse files
committed
test for no *js.Object struct
1 parent 296669c commit c01ba7c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

examples/features/features.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import (
88
"time"
99
)
1010

11+
// no *js.Object struct can only be manipulated by ViewModel.methods
1112
type Todo struct {
12-
*js.Object
13-
Time string `js:"time"`
14-
Content string `js:"content"`
13+
// *js.Object
14+
Time string //`js:"Time"`
15+
Content string //`js:"Content"`
1516
}
1617

1718
func NewTodo(content string) *Todo {
1819
t := &Todo{
19-
Object: js.Global.Get("Object").New(),
20+
//Object: js.Global.Get("Object").New(),
2021
}
2122
t.Time = time.Now().Format("15:04 05:06")
2223
t.Content = content
@@ -41,10 +42,6 @@ func (m *Model) Inc() {
4142

4243
func (m *Model) Repeat() {
4344
m.Str = strings.Repeat(m.Str, 3)
44-
}
45-
46-
func (m *Model) PopulateTodo() {
47-
m.Todos = append(m.Todos, NewTodo(m.Str))
4845
vm := vue.GetVM(m)
4946
println("Get(m):", vm)
5047
println("m keys:", js.Keys(m.Object))
@@ -58,8 +55,18 @@ func (m *Model) PopulateTodo() {
5855
println("integer from vm:", vm.Get("integer").Int())
5956
}
6057

58+
func (m *Model) PopulateTodo() {
59+
// m.Todos = append(m.Todos, NewTodo(m.Str))
60+
vm := vue.GetVM(m)
61+
todos := vm.Get("todos")
62+
todos.Unshift(NewTodo(m.Str))
63+
}
64+
6165
func (m *Model) ShiftTodo() {
62-
m.Todos = m.Todos[1:]
66+
// m.Todos = m.Todos[1:]
67+
vm := vue.GetVM(m)
68+
todos := vm.Get("todos")
69+
todos.Shift()
6370
}
6471

6572
func (m *Model) WhatTF() string {

examples/features/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</li>
3737
<input v-model="str" />
3838
<ul v-for="todo in todos">
39-
<li>{{todo.time}} - {{todo.content}}</li>
39+
<li>{{todo.Time}} - {{todo.Content}}</li>
4040
</ul>
4141
<p>{{str}}</p>
4242
</div>

0 commit comments

Comments
 (0)