Use rendered() for SPA layout chain, add jqhtml lifecycle docs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-12 07:19:23 +00:00
parent f625531b81
commit 2f96bb6276
85 changed files with 198 additions and 37 deletions

View File

@@ -848,8 +848,9 @@ class Spa {
// Create component
const component = $current_container.component(component_name, is_last ? args : {}).component();
// Wait for it to be ready
await component.ready();
// Wait for render to complete (not full ready - we don't need child data to load)
// This allows layout navigation to update immediately while action loads
await component.rendered();
if (is_last) {
// This is the action

View File

@@ -1017,9 +1017,11 @@ LIFECYCLE MANIPULATION METHODS
Method Summary (jqhtml v2.2.182+):
reload() - Restore this.data to defaults, call on_load(), then render()
render() - Re-renders with full lifecycle (waits for children, calls on_ready)
redraw() - Alias for render()
reload() - Restore this.data to defaults, call on_load(), then render()
render() - Re-renders with full lifecycle (waits for children, calls on_ready)
redraw() - Alias for render()
ready() - Returns promise that resolves when full lifecycle complete
rendered() - Returns promise that resolves when render complete (not children)
reload()
Re-fetch data and re-render - Restores this.data to on_create() state,
@@ -1105,6 +1107,40 @@ LIFECYCLE MANIPULATION METHODS
}
}
ready()
Wait for component to complete full lifecycle including all children.
Usage:
const component = $(element).component();
await component.ready();
// Component and all children are now fully loaded
Behavior:
- Returns promise that resolves when full lifecycle is complete
- Waits for on_load() of this component AND all descendants
- Waits for on_ready() of this component AND all descendants
- Use when: You need component to be fully interactive
rendered()
Wait for component's render to complete (does not wait for children's data).
Usage:
const component = $(element).component();
await component.rendered();
// DOM is rendered, but children may still be loading data
Behavior:
- Returns promise that resolves after render phase completes
- Does NOT wait for child components' on_load() or on_ready()
- Use when: You need DOM structure but don't need child data
- Faster than ready() when child data loading is unnecessary
Example - SPA layout navigation:
// Update nav active state without waiting for action to load data
await layout.rendered();
layout.$sid('nav').find('.active').removeClass('active');
layout.$sid('nav').find(`[href="${url}"]`).addClass('active');
SYNCHRONOUS REQUIREMENTS
CRITICAL: These lifecycle methods MUST be synchronous (no async, no await):