Skip to content

Commit

Permalink
docs(api): Update decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 16, 2023
1 parent 5ebab14 commit 347a82b
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions trame/decorators/klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ def can_be_decorated(x):


class TrameApp:
def __init__(self, server="server", namespace=""):
"""
Class Decorator for trame application.
This decorator can be used to automatically register methods to state.change, controller, trigger and life_cycle.
The parameter are used to define where to fine the server instance within the object and where a namespace for the variable name is stored.
"""
Class Decorator for trame application.
This decorator can be used to automatically register methods to state.change, controller, trigger and life_cycle.
The parameter are used to define where to fine the server instance within the object and where a namespace for the variable name is stored.
@TrameApp()
class ExampleApp:
def __init__(self):
self.server = get_server()
@TrameApp()
class ExampleApp:
def __init__(self):
self.server = get_server()
@change("var_name_1", "var_name_n")
def on_state_change(**kwargs):
pass
@change("var_name_1", "var_name_n")
def on_state_change(**kwargs):
pass
@controller.set("hello")
def hello(**kwargs):
pass
@controller.set("hello")
def hello(**kwargs):
pass
"""

"""
def __init__(self, server="server", namespace=""):
self.server_name = server
self.namespace_prefix = namespace

Expand Down Expand Up @@ -131,33 +131,35 @@ def decorate(f):


class Controller:
def __init__(self):
"""Controller decorators
"""Controller decorators
- once
- add
- add_task
- set
"""

- once
- add
- add_task
- set
"""
def __init__(self):
self.once = controller_decorator("once")
self.add = controller_decorator("add")
self.add_task = controller_decorator("add_task")
self.set = controller_decorator("set")


class LifeCycle:
def __init__(self):
"""Life Cycle decorators
"""Life Cycle decorators
- server_start
- server_bind
- server_ready
- client_connected
- client_exited
- server_exited
- server_reload
- server_start
- server_bind
- server_ready
- client_connected
- client_exited
- server_exited
- server_reload
"""
"""

def __init__(self):
self.server_start = controller_decorator("add")("on_server_start")
self.server_bind = controller_decorator("add")("on_server_bind")
self.server_ready = controller_decorator("add")("on_server_ready")
Expand Down

0 comments on commit 347a82b

Please sign in to comment.