You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for loading multiple imports per component (localization) #23
I'd like to see support for loading locale-specific i18n message files together with the actual view component. This would allow for route-splitted translation files which, as the view itself, are just loaded on demand e.g. for usage with IntlProvider by react-intl.
If there are messages it would probably be a good idea to use IntlProvider with the messages given for wrapping the dynamically loaded view. It might be also cool to use injectIntl for offering the intl API via props to the loaded view.
changed the title [-]Add support for loading multiple imports per component[/-][+]Add support for loading multiple imports per component (localization)[/+]on Mar 21, 2017
With the latest code parse I did a bit of renaming to help the API move towards supporting something like your request.
My initial idea is to allow an additional prop to be provided to an async component instance. Specifically a render callback function. The render callback would then receive the result of the render. Something like:
constAboutView=asyncComponent({resolve: (props)=>{const{ language }=propsreturnPromise.all([import("./views/About"),import("./views/About."+language+".json")])},passThroughProps: ['language']})<AboutViewlanguage="de"render={(resolved)=>{const[View,translations]=resolvedreturn<Viewtranslations={translations}/>}}/>
The props pass through to the resolver poses an interesting question though. This would affect our caching. We would have to cache a result per variation of prop. Therefore we may need to consider adding an additional configuration value to asyncComponent called something like passThroughProps that would allow you define which props to pass to asyncComponent. These props would then be used as keys in a cache map of sorts.
I just figure it would be nicer from the API standpoint to use named parameters/fields instead of array indexes and destructing. In this case we can't use Promise.all() as this does not work for objects... but it would be nicer from the usage standpoint. We could just return an objet in resolve() with { view: xx, translations: xx } and let the promise handling being done inside of asyncComponent.
I wonder what's the benefit of making the pass-through config required? Why not just pass-through all props?
Activity
[-]Add support for loading multiple imports per component[/-][+]Add support for loading multiple imports per component (localization)[/+]swernerx commentedon Mar 21, 2017
I tried implementing these requirements in style of your component in this file:
https://github.com/sebastian-software/edgestack/blob/master/src/api/common/createLazyComponent.js
But I would like working on a single solution instead of implementing too many alternatives.
ctrlplusb commentedon Apr 3, 2017
Hey @swernerx
Thanks for this suggestion.
With the latest code parse I did a bit of renaming to help the API move towards supporting something like your request.
My initial idea is to allow an additional prop to be provided to an async component instance. Specifically a render callback function. The render callback would then receive the result of the render. Something like:
The props pass through to the resolver poses an interesting question though. This would affect our caching. We would have to cache a result per variation of prop. Therefore we may need to consider adding an additional configuration value to
asyncComponentcalled something likepassThroughPropsthat would allow you define which props to pass toasyncComponent. These props would then be used as keys in a cache map of sorts.Thoughts?
swernerx commentedon Apr 4, 2017
Looks good.
I just figure it would be nicer from the API standpoint to use named parameters/fields instead of array indexes and destructing. In this case we can't use Promise.all() as this does not work for objects... but it would be nicer from the usage standpoint. We could just return an objet in resolve() with { view: xx, translations: xx } and let the promise handling being done inside of asyncComponent.
I wonder what's the benefit of making the pass-through config required? Why not just pass-through all props?
djeeg commentedon Apr 11, 2017
Perfect,
I want to try something like this
hoschi commentedon Apr 26, 2017
interesting, a lot of people solving the same problem :)
I did a prototype here https://github.com/hoschi/react-async-component/tree/feature/render
Here is an example usage:
This can be used to
As my use case is a bit different, I create another ticket this or next week.
hoschi commentedon May 9, 2017
I created issue #44 for my use case