Metro bundler inlines (ReactNative.)Platform.OS and (ReactNative.)Platform.select, so that when packaging for one platform, the code for the other platform is optimized away.
So if I had
[@bs.module "react-native"] [@bs.scope "Platform"] external os : string = "OS";
if (os === "ios") {
Js.log("ios");
} else {
Js.log("android");
};
this would get compiled by BuckleScript to
if (ReactNative.Platform.OS === "ios") {
console.log("ios");
} else {
console.log("android");
}
and Metro Bundler would inline ReactNative.Platform.OS and subsequently optimize the Android branch away for an iOS build.
However, with the current Rebolt bindings, I have
switch (Platform.os()) {
| IOS(_) => Js.log("ios")
| Android => Js.log("android")
};
which gets compiled by BuckleScript to
var match = Platform$Rebolt.os(/* () */0);
if (match) {
console.log("ios");
return /* () */0;
} else {
console.log("android");
return /* () */0;
}
This prevents the inlining/optimization from working.
Metro bundler inlines
(ReactNative.)Platform.OSand(ReactNative.)Platform.select, so that when packaging for one platform, the code for the other platform is optimized away.So if I had
this would get compiled by BuckleScript to
and Metro Bundler would inline ReactNative.Platform.OS and subsequently optimize the Android branch away for an iOS build.
However, with the current Rebolt bindings, I have
which gets compiled by BuckleScript to
This prevents the inlining/optimization from working.