pub struct RemoteSession { /* private fields */ }Implementations§
Source§impl RemoteSession
impl RemoteSession
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
Create a new remote session.
Sets up the engine with the component resolver and module, but does NOT
render yet. The initial render happens in [handle_hello].
Sourcepub fn on_route_enter<F>(&self, pattern: impl Into<String>, handler: F)
pub fn on_route_enter<F>(&self, pattern: impl Into<String>, handler: F)
Register a route-entry hook.
Called whenever the session’s router lands on pattern (via any
@router.push / @router.replace / @router.back dispatch).
The hook receives the extracted route params, a mutable handle
to the shared state map (keyed by lowercase module name; ""
= primary), and the session’s GlobalContext.
Typical use: load data for a :id / :postId route and write
it into the corresponding nested module’s state slot. The state
changes are flushed to the engine at the end of the surrounding
handle_action call, so any patches land
in the same WebSocket response.
session.on_route_enter("/comments/:postId", move |params, state, _ctx| {
let post_id = params.get("postId").cloned().unwrap_or_default();
let comments = load_comments(&db, &post_id);
if let Some(slot) = state.get_mut("comments") {
if let Some(obj) = slot.as_object_mut() {
obj.insert("postId".into(), Value::String(post_id));
obj.insert("comments".into(), serde_json::to_value(&comments).unwrap());
}
}
});Sourcepub fn router(&self) -> &Arc<HypenRouter> ⓘ
pub fn router(&self) -> &Arc<HypenRouter> ⓘ
The router driving this session.
The engine’s reserved router.* action namespace is wired to
this router automatically in Self::new — DSL authors get
@router.push / @router.replace / @router.back for free.
Callers that want programmatic nav, to subscribe to
on_navigate, or to attach a
ManagedRouter use this
handle.
Sourcepub fn context(&self) -> &Arc<GlobalContext> ⓘ
pub fn context(&self) -> &Arc<GlobalContext> ⓘ
The global context associated with this session.
Paired with Self::router; the session sets the router on the
context at construction so any attached ManagedRouter can find
it via context.router().
Sourcepub fn from_definition<S: State>(
def: Arc<ModuleDefinition<S>>,
components: ComponentRegistry,
) -> Self
pub fn from_definition<S: State>( def: Arc<ModuleDefinition<S>>, components: ComponentRegistry, ) -> Self
Create a session from a ModuleDefinition, automatically wiring up
typed action handlers, UI source, and resources.
This is the recommended way to create a RemoteSession when using the
ModuleBuilder API. It eliminates manual
SessionConfig construction and raw action handler closures.
§Example
let module = Arc::new(HypenApp::module::<MyState>("App")
.state(MyState::default())
.ui_file("./components/App/component.hypen")
.on_action::<()>("increment", |s, _, _| s.count += 1)
.build());
let session = RemoteSession::from_definition(module, components);Sourcepub fn from_definition_with_state<S: State>(
def: Arc<ModuleDefinition<S>>,
components: ComponentRegistry,
initial_state: S,
modules: Vec<ModuleSessionConfig>,
) -> Self
pub fn from_definition_with_state<S: State>( def: Arc<ModuleDefinition<S>>, components: ComponentRegistry, initial_state: S, modules: Vec<ModuleSessionConfig>, ) -> Self
Create a session from a ModuleDefinition with a per-client state
override and optional nested modules.
Use this when initial state varies per client (e.g., loaded from a database for the connected user).
§Example
let search_mod = Arc::new(HypenApp::module::<SearchState>("Search")
.state(SearchState::default())
.on_action::<()>("search", |s, _, _| { /* filter */ })
.build());
let session = RemoteSession::from_definition_with_state(
app_module.clone(),
components,
client_state,
vec![ModuleSessionConfig::from_definition(search_mod)],
);Sourcepub fn set_action_handler<F>(&self, handler: F)
pub fn set_action_handler<F>(&self, handler: F)
Set the action handler for the session’s primary module.
Called whenever a dispatchAction message arrives whose action
belongs to the primary module (i.e. engine.action_scope_for returns
None). The handler receives the action name, optional payload, and
current primary-module state, and must return the new state.
Nested-module handlers are installed internally by
from_definition_with_state.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session ID assigned to this client.
Sourcepub fn handle_hello(&self, client_session_id: Option<&str>) -> Vec<String>
pub fn handle_hello(&self, client_session_id: Option<&str>) -> Vec<String>
Handle the hello handshake. Returns [sessionAck, initialTree] as JSON.
If client_session_id is Some(id) and a SessionManager was used
to suspend that session earlier, the caller should call
handle_reconnect with the
PendingSession.saved_state BEFORE calling this method so the state
is restored before the initial render.
Call this either:
- When you receive a
hellomessage from the client, or - Immediately after connection (for clients that don’t send hello)
Sourcepub fn handle_message(&self, json: &str) -> Vec<String>
pub fn handle_message(&self, json: &str) -> Vec<String>
Handle an incoming JSON message. Returns response messages as JSON strings.
Sourcepub fn fire_disconnect(&self, session_info: &SessionInfo)
pub fn fire_disconnect(&self, session_info: &SessionInfo)
Fire the on_disconnect handler with a snapshot of the current
primary-module state. Call this when the last WebSocket connection
for the session drops and you’re about to suspend it via
[SessionManager::suspend_session].
No-op if no on_disconnect handler was registered on the
ModuleDefinition (i.e. the session was created via
RemoteSession::new without from_definition).
Sourcepub fn fire_reconnect(&self, session_info: &SessionInfo, saved_state: &Value)
pub fn fire_reconnect(&self, session_info: &SessionInfo, saved_state: &Value)
Fire the on_reconnect handler and apply the saved state to the
session. Call this when a client resumes a suspended session
(i.e. after [SessionManager::resume_session] returns
Some(pending)).
The handler receives a mutable reference to the current primary state (as JSON) and the saved state — it can choose to merge, replace, or ignore the saved state. If no handler is registered, the saved state replaces the primary state directly.
Sourcepub fn fire_expire(&self, session_info: &SessionInfo)
pub fn fire_expire(&self, session_info: &SessionInfo)
Fire the on_expire handler. Call this from the
[SessionManager] suspension’s on_expire callback when the TTL
elapses without a reconnect.
Auto Trait Implementations§
impl !Freeze for RemoteSession
impl !RefUnwindSafe for RemoteSession
impl !UnwindSafe for RemoteSession
impl Send for RemoteSession
impl Sync for RemoteSession
impl Unpin for RemoteSession
impl UnsafeUnpin for RemoteSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);