Replies: 1 comment
-
I vote for this Another use case showModal(PromptDialog, {title: 'Why?'})
.then(v => router.post(route('item.destroy', id), {v}))
.then(hideModal); Simple and straightforward, I hope for the future |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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