File: core_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 (25 lines) | stat: -rw-r--r-- 585 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
from trame.app import get_server

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

state.count = 2
state.double = 4
state.client_type = server.client_type


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


state.trame__template_main = """
    <div>
        <label>{{ client_type }}</label>
        <div>count = {{ count }}</div>
        <div>2 x count = {{ utils.fmt.bytes(double) }}</div>
        <input type="range" min="0" max="1000000" step="1000" v-model="count" />
    </div>
"""

server.start()