-
Notifications
You must be signed in to change notification settings - Fork 11
/
CroquetCounterUI.ns
80 lines (79 loc) · 1.87 KB
/
CroquetCounterUI.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Newspeak3
'Root'
class CroquetCounterUI usingPlatform: p = (
|
private Subject = p hopscotch Subject.
private Presenter = p hopscotch Presenter.
first ::= true.
getCroquetView = [p js global at: #theView].
croquetView_slot
|
) (
public class Counter = (
| public count <Integer> ::= 0. |
) (
) : (
)
class CounterPresenter onSubject: s <CounterSubject> = Presenter onSubject: s (
) (
public isKindOfCounterPresenter = (
^true
)
isMyKind: other = (
^other isKindOfCounterPresenter
)
scope = (
^'newspeak_croquet_counter'
)
definition = (
^row: {
label: subject count.
mediumBlank.
button: 'increment' action: [croquetView publish: scope event: #increment].
button: 'decrement' action: [croquetView publish: scope event: #decrement].
button: 'reset' action: [croquetView publish: scope event: #reset].
}.
)
croquetView = (
croquetView_slot isNil ifTrue: [ensureSubscriptions].
^croquetView_slot.
)
ensureSubscriptions = (
first ifTrue: [
first:: false.
croquetView_slot:: getCroquetView value.
croquetView subscribe: scope eventSpec: #model_increment handler: [:e | updateGUI: [subject increment]].
croquetView subscribe: scope eventSpec: #model_decrement handler: [:e |updateGUI: [subject decrement]].
croquetView subscribe: scope eventSpec: #model_reset handler: [:e | updateGUI: [subject clear]].
]
)
) : (
)
public class CounterSubject onModel: m <Counter> = Subject onModel: m(
) (
createPresenter ^ <CounterPresenter> = (
^CounterPresenter onSubject: self
)
public isKindOfCounterSubject = (
^true
)
isMyKind: other = (
^other isKindOfCounterSubject
)
public decrement = (
model count: count - 1
)
public count ^ <Integer> = (
^model count
)
public clear = (
model count: 0
)
public increment = (
'incrementing ' out.
model count: count + 1
)
) : (
)
) : (
)