OptimisticAction
OptimisticAction is a button preset for optimistic UI flows where the UI updates
immediately, then either commits or rolls back based on the server response.
Import
Basic Usage
OptimisticAction(
"Archive",
endpoint="/items/42/archive",
target="#item-42",
action_id="archive-42",
payload={"item_id": 42},
variant="warning",
)
Event Contract
OptimisticAction dispatches bubbling CustomEvents from the button:
faststrap:optimistic:applybefore request startsfaststrap:optimistic:commitafter successful responsefaststrap:optimistic:rollbackwhen request fails
Event detail includes:
actionIdendpointmethodtargetpayloadreason
Server Contract Recommendation
Use idempotent endpoints and return consistent error status codes for failed writes. Client listeners should:
- Apply temporary UI state on
apply - Finalize UI state on
commit - Restore previous UI state on
rollback
Notes
- Supported methods:
get,post,put,patch,delete - Unsupported methods raise
ValueError - Designed as an interaction preset; no Faststrap core API changes required