-
Notifications
You must be signed in to change notification settings - Fork 465
Dynamic import ergonomics #5593
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
One thought about how could it look like. What if ReScript introduce an let modulePromise = @import ModuleName.functionName
// or later, with syntax support
let modulePromise = import(ModuleName.functionName) Given that, along with JSX V4, the original example will be: module DynamicWidget = {
open Next.Dynamic
let make = dynamic(() => import(Widget.make), options(~ssr=false, ()))
}
// Then
<Suspense fallback={...}>
<DynamicWidget />
</Suspense> |
AFAIK, the EDIT: No 2. seems possible to be transformed to the component's path. It is not very different from the normal import in output js. |
module DynamicWidget = {
open Next.Dynamic
@react.component(dynamic)
let make = dynamic(() => import(Widget.make), { ssr: false })
}
// generated to
module DynamicWidget = {
open Next.Dynamic
type props = Widget.props // <-- 1
let make = dynamic(() => import(Widget.make), { ssr: false })
}
// output in js
var DynamicWidget = dynamic(() => import("./Widgets/Widget.bs.js"), { ssr: false }) // <-- 2 1 can be processed by jsx ppx. but 2 needs to be processed in js emitter, I guess. |
I'm shortly making a RFC post on the forums so we can start discussing a spec for dynamic imports in ReScript, and figure out all of the use cases we want to support, and how to support them best. Just a heads up 😃 |
Forum RFC posted here: https://forum.rescript-lang.org/t/rfc-dynamic-imports-in-rescript/3605 |
Almost. I mean whenever I use |
@mattdamon108 anything in here that should still affect the design of PPX V4? |
Thank you for asking. I don't think this feature should affect the PPX V4 for now. I agree to move to milestone 10.2. |
The dynamic import PR subsumes this. |
This is a follow up of the forum post
When it comes to dynamic import of modules in ReScript, it looks verbose. For example, given a React component, we can make its dynamic counterpart like this:
Three issues inconveniences:
makeProps
for myself. It should go away when JSX V4 will be released..bs.js
. Perhaps some magic possible to just mention a module name and the path comes out automaticallydefault
export (aren’t they?).The dynamic import problem is not specific to JSX / React components only.
import
might be used for regular modules as well. I wonder if ReScript can make dynamic imports a little more ergonomic.The text was updated successfully, but these errors were encountered: