File: life_cycle_client.py

package info (click to toggle)
python-trame-client 3.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,128 kB
  • sloc: python: 9,609; javascript: 3,897; sh: 9; makefile: 6
file content (45 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download
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
from trame.app import get_server
from trame.widgets import client, html
from trame.ui.html import DivLayout

server = get_server(client_type="vue2")

state = server.state
global_layout = None

state.a = 1
state.last_event = None


def add():
    state.a += 1


def add_div():
    with global_layout:
        html.Div("Hello")


with DivLayout(server) as layout:
    global_layout = layout
    layout.root.add_child(
        "a={{ a }} - LifeCycle {{ last_event }}<br> template_ts={{ tts }} <br> "
    )
    html.Button("a+", click="a+=1")
    html.Button("set(a+)", click="set('a', a+1)")
    html.Button("server", click=add)
    html.Button("modify layout", click=add_div)
    client.LifeCycleMonitor(
        type="emit",
        created="last_event += 'created '",
        before_mount="last_event += 'beforeMount '",
        mounted="last_event += 'mounted '",
        before_update="last_event += 'beforeUpdate' ",
        updated="last_event += 'updated '",
        before_destroy="last_event += 'beforeDestroy '",
        destroyed="last_event += 'destroyed '",
    )


if __name__ == "__main__":
    server.start()