-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
<:Async> component #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is there a work around until the async component is created? |
I feel like this could easily be implemented in userland if we provided a way to pass components as properties.. (#640) |
Yea, I totally agree and component passing would provide lots of other benefits as well. |
Just an idea: <Widget loading:LoadingComponent error:ErrorComponent foo='{{bar}}'>
contents go here
</Widget>
<script>
import LoadingComponent from './LoadingComponent.html';
import ErrorComponent from './ErrorComponent.html';
const Widget = import('./Widget.html');
export default {
components: {
LoadingComponent,
ErrorComponent,
Widget
}
};
</script> Every component during compilation should be checked if it is an instance of Promise and processed in a different way. Will it work? |
I think this is now effectly handled with #952 |
Not quite — #952 addresses the problem of async data, but not async components, i.e. you can't lazily load the <button on:click='set({ chatting: true })'>
chat to a customer service representative
</button>
{{#if chatting}}
<ChatToACustomerServiceRepresentative/>
{{/if}} It will be possible to do that with dynamic components though, which are almost ready (#971): {{#if chatting}}
<LazyLoad src='/components/ChatToACustomerServiceRepresentative.html'>
<div>loading...</div>
</LazyLoad>
{{/if}} <!-- LazyLoad.html -->
{{#await promise}}
<slot></slot>
{{then constructor}}
<:Component {constructor}/>
{{catch error}}
<p>oops! please try reloading the page</p>
{{/await}}
<script>
export default {
computed {
promise: src => import(src)
}
};
</script> (I'm glossing over some details, of course — not least of which is the fact that there's no way to pass arbitrary props down via |
Ah, yes sorry it's because so far all my code has been bundled in a single app so I was thining is makes barely makes any difference once the code is on the page. So the idea is you'd compile out separate components and then their source is dynamically fetched and loaded? Wouldn't that lead to calls for code splitting too? Edit: yes this will be amazing 👍 |
In Ractive, I'm following this approach:
DemoSee https://github.com/ceremcem/ractive-synchronizer Advantages
|
Been trying to hack together asynchronous routing w/o Sapper and this would help greatly |
Hi guys, I am fairly new to Svelte and already trying to do complicated stuff with it, so I hope you will bear with me. I am working on a generalization of the problem described in this GitHub issue based on state machines. My idea is an API like: <Async on:event={handleEvent} startWith="loading">
<LoadingComponent slot="loading" task={asyncLoadWidget} />
<ErrorComponent slot="error" />
<Widget slot="loaded" />
<Async /> The The The Needless to say, the approach is pretty generic:
My question is, given that component events do not bubble, if On another note, what do you think at first sight about the proposed API? |
I finalized a proof of concept for Suspense. This example was useful and outlined some benefits and some difficulty of Svelte's compiler approach. I will address this in a new issue. I assume the async component loading would fit in the same frame. |
is the <:Component/> available in v3? |
@mrkishi how does one dynamic import a component in? |
ah yeah, per Rich's comment, |
Can you post an example please? |
Something like this REPL should do it. |
As I write this, the poll above barely favors having a new syntax, 21 to 18, but I still don't think this is something we want to do. An async component is something that's trivial to do with the tools that already exist, and without having to implement or maintain or document anything new in the compiler. Closing. |
A proposal for first-class async component support:
Behind the scenes that would become roughly equivalent to this...
...except that you wouldn't need to declare
Widget
ahead of time.It would get transpiled to
import('./Widget.html').then(...)
indom
mode, but could be an inlinerequire('./Widget.html')
inssr
mode.Advantages of this approach over a 'just use a component' approach, for the benefit of @TehShrike 😉 :
<ReactCSSTransitionGroup>
andin:fade
.<Async>
component (as opposed to<:Async>
) would have to do its work inoncreate
, which doesn't run on the server. With<:Async>
we can load the component synchronously withrequire(...)
and generate markup without 'loading...' messages.The text was updated successfully, but these errors were encountered: