-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
feat: add dynamic props #283
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thans for this contribution :) I definitely see the value in this, although I do have some feedback on the implementation, if you can please take a look!
prop resolution moved below as adviced and made async fixed the formatting
Following is an example that uses await. '/foo': wrap({
component: Foo,
props: {
staticProp: 'this is static',
dynamicProp: async () => Promise.resolve(`this is dynamic - ${new Date}`),
anotherProps: () => `Just works!`,
delayed: async () => await fetch(`https://api.chucknorris.io/jokes/random`).then(i => i.json()).then(i => i.value),
}
}), |
@ItalyPaleAle any updates? |
@yaameen Apologies for the delay, had a crazy week :) I have reviewed the PR once again and pushed a small commit to your branch to fix some formatting. There are however 2 things that make me nervous about merging this and I'd like to ask if you could please do more testing (incl. perhaps writing unit tests) in that regards:
|
Removes promise.resolve while resolving user provide props It now determines functions, promises and otherwise and resolves the prop
Actually it was a mistake putting the prop resolution with in the if block. Also speaking of retaining the component I am failing to produce any occasion where the component is the same but it is not re-mounted when path changes (wild card routes are an exception here). Refer to the following repl. https://svelte.dev/repl/0d1885829adf467faa5cd432d766a43a?version=3.53.1 Also in the following snippet where svelte-spa-router/Router.svelte Line 539 in 86c99fe
like so Line 55 in 86c99fe
I was wondering is that the reason the component is always re-mounted? Or am I missing something here?
Than you for the feedback, I have simplified the prop resolution where function callback are involved only where required. |
Any update @ItalyPaleAle on this? |
It lets you pass dynamic props to the loaded component. It adheres to the routing cycle and renders components only after the props are resolved. It raises propsFailed event for each prop when the prop fails to resolve.
Follows how you would pass dynamic props to your component.