-
Notifications
You must be signed in to change notification settings - Fork 259
/
greeter2.py
40 lines (27 loc) · 993 Bytes
/
greeter2.py
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
"""
Example similar to greeter1.py, but with reactions defined outside of
the class. This style is generally not recommended.
"""
from flexx import event
class Person(event.Component):
first_name = event.StringProp('Jane', settable=True)
last_name = event.StringProp('Doe', settable=True)
children = event.ListProp([], doc='The children of this person')
@event.action
def add_child(self, child):
self._mutate_children(self.children + [child])
p1 = Person()
# Actions defined outside the class
@p1.reaction('first_name', 'last_name')
def greet_explicit1(*events):
for ev in events:
p = ev.source
print('Hi explicit1 %s %s' % (p.first_name, p.last_name))
def greet_explicit2(*events):
for ev in events:
p = ev.source
print('Hi explicit2 %s %s' % (p.first_name, p.last_name))
p1.reaction(greet_explicit2, 'first_name', 'last_name')
p1.set_first_name('Jane')
p1.set_last_name('Jansen')
event.loop.iter()