-
Notifications
You must be signed in to change notification settings - Fork 348
Open
Labels
Description
it's currently pretty hard to get a type-safe dynamic import using BuckleScript. it's even harder to use React.lazy.
how would you feel about having a PPX:
module ReactLazy = {
[@bs.module "react"]
external make:
(unit => Js.Promise.t({. "default": React.component('a)})) =>
React.component('a) =
"lazy";
};
[@react.lazy]
module MyComponentLazy = MyComponent;
// that would expand to something like:
module MyComponentLazy: MyComponentType = {
module type MyComponentType = (module type of MyComponent);
[@bs.val] external myComponent: (module MyComponentType) = "undefined";
include (val myComponent);
[@bs.val]
external import:
([@bs.as "MODULE_RELATIVE_PATH"] _, unit) => Js.Promise.t(module MyComponentType) =
"import";
let make =
ReactLazy.make(() =>
import()
|> Js.Promise.then_((module MyComponent: MyComponentType) =>
Js.Promise.resolve({"default": MyComponent.make})
)
);
};relekang, baransu, jchavarri, cometkim, jumoel and 5 more