Class State#
Defined in File State.h
Class Documentation#
-
class State#
State shared on the client.
Public Functions
-
State(Router &router, const nlohmann::json &init_value = {}, bool sync = true)#
State constructor.
- Parameters:
router – The Router to use
init_value – The initial state
sync – Sync among server and clients
-
nlohmann::json get() const#
Get the current state value.
Note that the state value is managed by the UI thread, so this will block until the UI thread can be synced.
- Returns:
The state value
-
void set(const nlohmann::json &new_value)#
Set a new state value.
- Parameters:
new_value – The new state value
-
Karana::Core::id_t onChange(std::function<void(const nlohmann::json &state)> on_change)#
Add a callback invoked when the state changes.
- Parameters:
on_change – The callback
- Returns:
A unique id for the callback
-
State(Router &router, const nlohmann::json &init_value = {}, bool sync = true)#