state

class trame_server.state.State(translator=None, internal=None, commit_fn=None, hot_reload=False, ready=False)

Flexible dictionary managing a server shared state. Variables can be accessed with either the [] or . notation.

client_only(*_args)

Tag a given set of variable name(s) to be client only. This means that when they get changed on the client side, the server will not be aware of their change and no network bandwidth will be used to maintain the server in sync with the client state.

Parameters:

*_args

A list a variable name

to_dict()

Flush current state modification and return the resulting state state as a python dict.

has(key)

Check is a key is currently available in the state

setdefault(key, value)

Set an initial value if the key is not present yet

is_dirty(*_args)

Check if any provided key name(s) still has a pending changed that will need to be flushed.

is_dirty_all(*_args)

Check if all provided key name(s) has a pending changed that will need to be flushed.

dirty(*_args)

Mark existing variable name(s) to be modified in a way that they will be pushed again at flush time.

clean(*_args)

Save pending variable(s) and unmark them as dirty. This will prevent change listener(s) to react or the client to be aware of any change.

update(_dict)

Update the current state dict with the provided one

flush()

Force pushing modified state and execute any @state.change listener

property initial

Return the initial state without triggering a flush

change(*_args, **_kwargs)

Use as decorator @server.change(key1, key2, …) so the decorated function will be called like so _fn(**state) when any of the listed key name is getting modified from either client or server.

Parameters:

*_args

A list of variable name to monitor