Drafter.Runtime.Shared (drafter v0.3.1)

Copy Markdown View Source

Runtime backend for shared multi-user sessions (e.g. an SSH chat served to many clients).

Wraps the Callback backend but routes app state changes through a the shared-state server: when the app produces new state, it is pushed to the shared server, which broadcasts {:shared_state_updated, state} to every connected session. Each session merges its per-session mount_props over the shared state and re-renders, so all clients stay in sync while keeping their own view-local props.

Selected per shared session at runtime, via the session's process dictionary, rather than by the app module. The same app can run standalone or shared.

Summary

Functions

Runs the app's handle_event/2 and pushes any new state to the shared server.

Runs the app's handle_event/3 and pushes any new state to the shared server.

The current shared state merged with this session's props.

Adopts a broadcast {:shared_state_updated, new_state} as this session's state.

Functions

handle_input(app, event, state)

@spec handle_input(module(), term(), term()) :: term()

Runs the app's handle_event/2 and pushes any new state to the shared server.

The result is returned unchanged; only {:ok, state} and {:ok, state, actions} trigger a broadcast.

handle_message(app, name, data, state)

@spec handle_message(module(), atom(), term(), term()) :: term()

Runs the app's handle_event/3 and pushes any new state to the shared server.

Broadcasts under the same conditions as handle_input/3.

mount(app, props)

@spec mount(module(), map()) :: term()

The current shared state merged with this session's props.

With no shared-state server in the process dictionary, falls back to Drafter.Runtime.Callback.mount/2. Where both carry a key, props wins.

on_message(app, msg, state)

@spec on_message(module(), term(), term()) :: term()

Adopts a broadcast {:shared_state_updated, new_state} as this session's state.

This session's :drafter_mount_props are merged over the incoming state, so view-local props survive a broadcast. Any other message delegates to Drafter.Runtime.Callback.on_message/3.

ready(app, state)

@spec ready(module(), term()) :: term()

Delegates to Drafter.Runtime.Callback.ready/2.

refresh_rate(app)

@spec refresh_rate(module()) :: Drafter.Runtime.refresh_rate()

Delegates to Drafter.Runtime.Callback.refresh_rate/1.

scroll_active(app, state)

@spec scroll_active(module(), term()) :: term()

Delegates to Drafter.Runtime.Callback.scroll_active/2.

scroll_idle(app, state)

@spec scroll_idle(module(), term()) :: term()

Delegates to Drafter.Runtime.Callback.scroll_idle/2.

timer(app, timer_id, state)

@spec timer(module(), term(), term()) :: term()

Delegates to Drafter.Runtime.Callback.timer/3.

Timer results are not broadcast to other sessions.