8 scenario tổng hợp: chọn đúng sức mạnh Inertia
Trang này không dạy API theo từng feature. Mỗi scenario bắt đầu từ vấn đề sản phẩm rồi mới chọn capability Inertia.Decision map nhanh
Scenario 1 — Admin table có search/filter/sort
Requirement:Scenario 2 — Dashboard có KPI query chậm
Requirement:Scenario 3 — Edit drawer/modal
Requirement:isDirty, errors, processing và key theo entity identity.
Nếu modal unmount khi đóng và request dài, cần quyết định rõ request nên tiếp tục hay bị cancel.
Scenario 4 — Toggle bookmark/favorite/status
Requirement:Scenario 5 — Upload avatar/file
Requirement:Scenario 6 — Export report chạy background
Requirement:Scenario 7 — Activity feed rất dài
Requirement:Scenario 8 — Gọi API thứ ba không phải page visit
Ví dụ search postcode từ external service hoặc preview một API endpoint. Không phải request nào cũng nên trở thành Inertia navigation. Với v3,useHttp phù hợp cho HTTP request độc lập nhưng vẫn muốn lifecycle state tương tự form.
Mental model:
Anti-pattern map
Câu hỏi tự kiểm tra trước khi code
- State này thuộc URL, server, form hay interaction local?
- Request này là page visit hay HTTP call độc lập?
- Prop nào thật sự cần cho first paint?
- Khi filter, prop nào cần refresh?
- Có thể prefetch vì user nhiều khả năng click không?
- Mutation có đủ nhỏ và reversible để optimistic không?
- Failure sẽ rollback UI thế nào?
- Back/Forward có restore đúng mental model không?