-
Notifications
You must be signed in to change notification settings - Fork 396
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
Partial-based alternative to proxies - incl async components - RFC #3111
Conversation
or - second swing at replacing parser transforms with a runtime construct
async components get support for wrapping the loaded component macro partials get a render hook
So this means reserved partial names, yes? |
…p turn also fills out remaining bits of partial test suite along with a few other random places
For those wondering about the reserved partial names, yes, this introduces three new special names that only apply if a component happens to be async:
Only the first two are supplied by the user e.g. <cmp>
{{#partial async-loading}}loading...{{/partial}}
{{#partial async-loaded}}<div burst-like-an-alien-in>{{>component}}</div>{{/partial}}
</cmp> Notice that the I chose those names because there's not a lot of wiggle room for mistaking what they do. I'm certainly open to suggestions on any naming if there are any other opinions 😄 |
Here's the full skinny on async components support in this PR:
|
…g fragment this allows a method to set a local context alias for the macro that isn't shared by any other nodes that happen to be in the same parent fragment
I have pushed out a demo build to npm as It also occurred to me that there should probably be an |
…n rejected async component also add async-failed special partial for async components
There's now an I feel like this is pretty well done and is much better than the proxy version. The only thing that seems like it would be a near-necessity would be having the ability to block same-named partials from being loaded within the nested template by allowing a partial registry on the macro. Any objections to using the partial registry for macro partials rather than some other registry? Either way, the partial vdom item will be responsible for them. Any objections to going ahead and merging this as experimental to be made available in the next 0.9 release? |
LGTM 👍 |
When something fails, we might want to show something via |
That's a bit beyond the scope of what ractive can handle. You'd need to cover that in the promise that you hand to ractive e.g. MyComponent: () => import('MyComponent.html').then(module => module.default, error => {
// here's your opportunity to do advanced error handling/retry
}); |
Description:
This is an alternative version of #3106 that builds on top of partials rather than introducing a new vdom construct. I have dubbed the updated partial items super partials or macro partials. There aren't too terribly many functional differences between this an the proxy PR, notably
proxy
is replaced withmacro
e.g.Ractive.macro( ( handle, attrs ) => ..., { options } )
new Ractive({ partials: { macro: Ractive.macro(...) } })
setTemplate
method that can be called at any timeThis also adds support for async components - components that are initially set as a promise for a component or a function that returns a promise for a component - by using an inline macro partial that resets when the component constructor becomes available. You can even specify a loading placeholder by passing a special inline partial e.g.
It might make sense to have an
async-loaded
partial too, to allow cross-fade transitions when the component loads in.Note that an external dynamic async plugin would still be easily available if you prefer the
<Async component="{{name}}" />
-style usage.Status
This isn't exactly complete, as there are still quite a few tests that need to be added, most notably regarding plain partial syntax that resolves to a macro partial. I think a few hooks would be nice to, likeThere are now tests, and I think the hooks are appropriately set up.render
andunrender
. There's ateardown
, but in hindsight, it should probably be moved tounbind
rather thanunrender
on the host partial.I will be pushing out a demo build to npm once I've covered a few more bases. I'll add some more description and examples once that's done. Until then, if you're intereseted, you can take a look at the included tests to kinda get an idea of what you can do with this.See this comment for published info and a playground.
Fixes #3099