You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allowed straightforward loading/success/failure indication in a standard JavaScript native way and allowed for easy Promise consumption wherever needed.
Currently, when loading/success/failure indications are needed, we can only make use of the provided Inertia hooks:
As you can probably tell this approach is very boilerplate-y and quickly gets cumbersome. But also, end users only have access to Inertia specific data in those hooks, nothing about the Axios response which can be useful in many situations.
Suggestion
I would like to propose the comeback of Promises as a result of all Inertia requests and, where possible, provide access to the underlaying Axios/Inertia objects.
As of now, this would include (I think it's an exhaustive list) the following elements:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there @joetannenbaum 👋
Was looking at the on-going async-requests branch and though I'd chime in with some questions/feedback if you'd indulge me.
Prelude
Prior to #208 Inertia allowed for visit request promises to be consumed by end users:
This allowed straightforward loading/success/failure indication in a standard JavaScript native way and allowed for easy Promise consumption wherever needed.
Currently, when loading/success/failure indications are needed, we can only make use of the provided Inertia hooks:
And when a Promise is needed as a result of the request being made, a Promise wrapping the request needs to be constructed manually:
As you can probably tell this approach is very boilerplate-y and quickly gets cumbersome. But also, end users only have access to Inertia specific data in those hooks, nothing about the Axios response which can be useful in many situations.
Suggestion
I would like to propose the comeback of Promises as a result of all Inertia requests and, where possible, provide access to the underlaying Axios/Inertia objects.
As of now, this would include (I think it's an exhaustive list) the following elements:
import { AxiosResponse } from 'axios' import { fireErrorEvent, fireInvalidEvent, fireSuccessEvent } from './events' import { History } from './history' import modal from './modal' import { page as currentPage } from './page' import { poll } from './poll' import { RequestParams } from './requestParams' import { SessionStorage } from './sessionStorage' import { ErrorBag, Errors, LocationVisit, Page } from './types' import { hrefToUrl, isSameUrlWithoutHash, setHashIfSameUrl } from './url' export class Response { // public async handle() { // + return this.requestParams.params.onSuccess(currentPage.get()) } }
But why? What problems/usecases would be solved?
Quality of life elements:
Usecases
Any scenario where consuming a Promise and/or the Request/Response is needed.
A very contrived example:
Ps.: All code provided should only serve as examples and starting points of course :)
Beta Was this translation helpful? Give feedback.
All reactions