Skip to content

Commit 3a7f8f2

Browse files
committed
docs: update basic example with new TrameApp
1 parent 1361bbc commit 3a7f8f2

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

docs/vitepress/examples/core/basics.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The examples presented below are meant to be executed and explored so you can un
2020
<<< @/../../examples/core_features/multi_layout.py
2121
:::
2222

23-
## Life Cycle
23+
## Life Cycle
2424

2525
<<< @/../../examples/core_features/life_cycle.py
2626

@@ -30,7 +30,7 @@ Trame as opposed to many frameworks out there is stateful which make things more
3030

3131
For that reason, the "hot reload" is at the execution and not on file save.
3232

33-
Basically, with trame, you need to interact with the application in order to re-excute some new code rather than saving your file and getting the new app ready to go. In fact you can have pieces of your application that will properly execute the edited code, while other will be stuck with the original version.
33+
Basically, with trame, you need to interact with the application in order to re-excute some new code rather than saving your file and getting the new app ready to go. In fact you can have pieces of your application that will properly execute the edited code, while other will be stuck with the original version.
3434

3535
Once hot-reload is enabled by either using the `TRAME_HOT_RELOAD` environment variable or by using the extra `--hot-reload` arg, only the methods executed on the controller or via `@state.change` properly re-evaluate the new code version. If you want to enable such behavior on your own function, you can use the `@trame.decorators.hot_reload` decorator.
3636

@@ -40,4 +40,6 @@ But in the following example, you can use `watchdog` to execute the UI update on
4040

4141
## Class for trame application
4242

43-
<<< @/../../examples/core_features/app.py
43+
<<< @/../../examples/core_features/app.py
44+
45+
Then with such a class that inherit `trame.app.TrameApp` you can instantiate it and return it to display its user interface.

examples/core_features/app.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
from trame.app import get_server
2-
from trame.decorators import TrameApp, change, controller, life_cycle, trigger
1+
from trame.app import TrameApp
2+
from trame.decorators import change, controller, life_cycle, trigger
33
from trame.ui.html import DivLayout
44
from trame.widgets import html
55

66

7-
@TrameApp()
8-
class App:
7+
class App(TrameApp):
98
def __init__(self, name=None):
10-
self.server = get_server(name)
11-
self.ui()
12-
13-
@property
14-
def state(self):
15-
return self.server.state
16-
17-
@property
18-
def ctrl(self):
19-
return self.server.controller
9+
super().__init__(server=name)
10+
self._build_ui()
2011

2112
@trigger("exec")
2213
def method_call(self, msg):
@@ -34,8 +25,8 @@ def one_slider(self, resolution, **kwargs):
3425
def on_ready(self, *args, **kwargs):
3526
print("on_ready")
3627

37-
def ui(self):
38-
with DivLayout(self.server):
28+
def _build_ui(self):
29+
with DivLayout(self.server) as self.ui:
3930
html.Input(
4031
type="range",
4132
min=3,

0 commit comments

Comments
 (0)