File: reactive_state.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 (29 lines) | stat: -rw-r--r-- 570 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
from trame.app import get_server
from trame.widgets import html
from trame.ui.html import DivLayout

server = get_server()
server.client_type = "vue2"
state, ctrl = server.state, server.controller

state.count = 2
state.double = 4


@state.change("count")
def update_count(count, **kwargs):
    state.double = 2 * int(count)


with DivLayout(server) as layout:
    html.Div("count = {{ count }}")
    html.Div("2 x count = {{ double }}")
    html.Input(
        type="range",
        min=0,
        max=10,
        step=1,
        v_model="count",
    )

server.start()