Runtime
Overview
This page covers:
the runtime resource model
the
document_id + absolute_pathAPI mappingfont/image resource queries
template instances
This page does not cover JSON field tables; for field details, see the per-module pages.
Runtime Resource Model
The parser ultimately resolves resources into a runtime Document:
a top-level
screen->Document.screensa top-level non-
screenviewasset ->Document.templates
The Runtime also maintains three kinds of non-document global resources:
global
fontglobal
imageglobal
theme
Then Runtime handles:
document registration
eager screen pre-creation
dynamic screen lazy creation
template instantiation
path indexing
events and bindings
Current bindings rules:
a
bindingskey uses a publiccamelCasedotted patha
bindingsvalue is the local key in the current node path scope, without a prefixthe runtime actually locates a binding by
document_id + absolute_path + local_keyprefer reading/writing via
Runtime::set_binding_value(document_id, absolute_path, key, value),Runtime::set_binding_values(document_id, updates), orView::set_binding_value(key, value)
Current Public API Mapping of Protocols
Any Node Query
find_view(document_id, absolute_path)View::find_view(path)
Notes:
find_view(document_id, absolute_path)can currently query any instantiated nodeall public paths use Unix-style absolute paths, e.g.
/about/header/title
Node Status and Runtime Operations
get_view_state(view, kind)/get_view_state(document_id, absolute_path, kind): read a node's runtime state (ViewStateKind)scroll_view_to_visible(document_id, absolute_path, animated = true)/scroll_view_to_visible(view, animated = true): scroll the target node into the visible areaset_view_src(document_id, absolute_path, src): directly update an image node'ssrcprocess_backend(): drive one backend processing pass (events, animations, refresh, etc.); usually called periodically in the host main loop
Template Instance
create_view(document_id, template_id, parent_absolute_path, instance_id)destroy_view(document_id, absolute_path)
Where:
template_idis the top-level template idparent_absolute_pathis the parent's absolute pathinstance_idis explicitly provided by the callerdestroy_view(...)can only delete a non-screensubtree
Event Subscription
subscribe_event_action(document_id, action, handler)subscribe_event_action_with_id(document_id, action, handler)unsubscribe_subscription(subscription_id)View::on_event(type, handler)Button::on_click(handler)
Notes:
subscribe_event_action(...)uses exactdocument_id + actionmatchingsubscribe_event_action_with_id(...)uses the samedocument_id + actionrouting and returns aSubscriptionIdwithin the same document, a statically declared non-empty
actionmust be globally uniquemultiple instances from a template definition can share the same
action; tell sources apart viaevent.path/event.node_idthe new interface allows pre-registration: you can register before the target template instance has been created
subscribe_event_action(...)returns aScopedConnection; the connection disconnects automatically on destructionsubscribe_event_action_with_id(...)returns aSubscriptionId; suitable when you need to record the subscription identity or disconnect explicitly laterunsubscribe_subscription(subscription_id)can explicitly disconnect a subscription obtained viawith_id; it returns failure for an invalid or already-disconnected idView::on_event(...)relies on a concrete, already-queryable instance and does noactionstring filtering
Runtime Animation
start_view_animation(document_id, absolute_path, animation, completed_handler = {})start_view_animation_with_id(document_id, absolute_path, animation, completed_handler = {})start_view_animation_with_result(document_id, absolute_path, animation, completed_handler = {})start_view_animation(view, animation, completed_handler = {})start_view_animation_with_id(view, animation, completed_handler = {})start_view_animation_with_result(view, animation, completed_handler = {})
Notes:
this set of APIs starts a view animation directly at runtime, without relying on
animationspre-declared in the node JSON.currently recommended for: -
placement.x-placement.y-placement.width-placement.height-imageProps.angle-imageProps.offsetX-imageProps.offsetYanimation.propertyreusesAnimationProperty; currently supports at least: -Opacity-X-Y-Width-Height-Scale-Angle-OffsetX-OffsetYanimation.easingreusesAnimationEasing; currentlylinearandeaseIncover common runtime scenarios.start_view_animation(...)returns aScopedConnection; the animation is canceled on destruction.start_view_animation_with_id(...)returns aSubscriptionId; pair it withunsubscribe_subscription(subscription_id)to cancel actively.start_view_animation_with_result(...)returns aRuntimeAnimationStartResult, bringing back both aSubscriptionIdand start-result info, useful when the start fails or completes immediately.a new animation of the same animation property on the same view overrides the previous one.
completed_handlerfires only when the animation completes naturally; if the animation is canceled, the completion callback does not fire.
Resource Query
list_font_resources(document_id)list_image_resources(document_id)
Notes:
a font query returns the Runtime's currently globally visible font resource set
list_supported_fonts(language = "")returns font ids, not full descriptorsan image query still returns, by
document_id, the document's currently visible image resources, including the documentimageSetand Runtime global imagesa Runtime global image can be registered before
load_file(); a${image.<id>}in the document resolves to it during load validationwhen size is not given explicitly,
register_image(...)asks the backend to completewidth/heightfrom image metadataduring document load, the backend preload hook preloads the current document
imageSetand Runtime global images; missing or invalid formats failload_file()/load_json()rather than deferring failure to first displayunregister_image(id)removes the resource from the Runtime global image table and releases the backend's preload reference to that imagefor image resources with the same name, the document
imageSetis preferred, then the Runtime global image
Binding Batch Update and Incremental Apply
Runtime::set_binding_values(document_id, updates)can write multipleBindingValueUpdategroups at once.the Runtime merges, per node, the props/style/layout/placement apply masks triggered by the batch; a node usually re-applies a given domain only once in a batch.
initial creation, document reload, and resource refresh still use a full apply; the high-frequency binding update path uses precise masks.
the animation API modifies backend node attributes directly and does not write back to the binding store. If the app layer caches binding values itself, invalidate the cache after the animation ends or is canceled, or force-write to overwrite the post-animation real state.
Delayed Update Policy for Languages and Themes
The Runtime's default API keeps immediate-update semantics:
set_language(language)validates the language, updates the Runtime's current language, and immediately reapplies style to all loaded documentsset_theme(theme_id)validates the theme, updates the Runtime's current theme, and immediately reapplies style to all loaded documents; a file-backed document using aThemevariant re-parses its rootupdate(document_id, file_path, environment)re-parses a single document; use it to let a newEnvironmentaffect variants, constant text, and initial binding values
If the app caches several loaded documents at once, a language or theme switch may not want to refresh all loaded pages synchronously on the display task. The caller can explicitly use Runtime lazy updates:
set_language(language, false)updates the Runtime's current language and the loaded tree's environment record, and marksenvironment_dirtyinside the Runtimeset_theme(theme_id, false)updates the Runtime's current theme; an ordinary document is markedstyles_dirty, while a file-backed document using aThemevariant is markedenvironment_dirtybefore accessing a target document in
mount_screen(...),find_view(...),create_view(...),subscribe_event_action(...), etc., the Runtime callsrefresh_document_if_dirty(...)to honor dirty updatesrefresh_document_if_dirty(...)handles only ``environment_dirty``: whenenvironment_dirtyis set, it runs an internalupdate(...)on a document loaded viaload_file(...)and clears environment dirty on successstyles_dirtyis not handled by the unified dirty pass: it is honored at specific access points; e.g.mount_screen(...)reapplies style only to the mounted subtree; it can also be honored explicitly byset_theme(theme_id)/reapply_styles(document_id)a non-file-backed document has no re-parsable root file and cannot fully honor lazy environment updates; such documents need the default immediate API or an explicit
update(...)by the calleran unloaded document needs no dirty mark; the first
load_file(...)directly uses the caller's currentEnvironmentand the Runtime theme