aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Higher-level pattern for async data loading

Open SteveSandersonMS opened this issue 8 years ago • 3 comments

We've had an internal request to consider ways of loading data without having to implement the usual if (data == null) { loading... } else { show data } in the markup, possibly also without overriding OnInitAsync or similar to put in the load logic.

Sketch:

<DataSource Url="people/@id" TResult=Person>
    <BeforeLoaded>Loading person @id...</BeforeLoaded>
    <OnError>Sorry, there was a problem. The response was @context.StatusCode.</OnError>
    <AfterLoaded Context="person">
        @person.Name is @person.Age years old
    </AfterLoaded>
</DataSource>

This doesn't really have to be baked into the core, but we might want this to appear in the default project template.

SteveSandersonMS avatar Nov 06 '18 09:11 SteveSandersonMS

Looks nice but please remember about authentication. Application can read data from different data sources and each one can require different authentication (JWT token) or some special request headers. Of course it is good to have a single sign-in experience, but it is not always possible.

Andrzej-W avatar Nov 06 '18 14:11 Andrzej-W

it might be better to mark the property as Async and conditionally render, only after the property has value

dlr1 avatar Nov 06 '18 15:11 dlr1

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

mkArtakMSFT avatar Oct 19 '22 19:10 mkArtakMSFT