Closed safareli closed 7 years ago
Oh! Yep! Let's define an ADT
data BuiltInTheme = Infographic | Macarons | Roma | Shine | Vintage | Dark
Then define a func from it to string like
builtInThemeRoute :: BuiltInTheme -> String
builtInThemeRoute = case _ of
Roma -> "echarts/theme/roma"
_ -> ...
builtinTheme :: BuiltInTheme -> Theme
builtinTheme = case _ of
Roma -> "roma"
_ -> ...
Then define a func that registers builtintheme
foreign import registerBuiltin_ :: String-> Eff _ Unit
registerBuiltin :: BuiltInTheme -> Eff _ Theme
registerBuiltIn bit = builtinTheme bit <$ registerBuiltin_ (builtinThemeRoute bit)
and in Theme.js
exports.registerBuiltIn_ = function(route) {
return function() {
require(route);
};
};
This way it's cleaner that registering builtin themes are effectful and they're actually predefined. And preserves notion of themes being open to extension by outside code.
@cryogenian the option looks nice!
But it might have issues with dead code elimination. I think code analyzers will not be able to determine required pathes which are dynamic, if that issue is not a problem Will implement it as you pointed out.
I would recommend not relying on dynamic requires.
@natefaubion In this case it's actually isn't require
but just an effect that registers an object as theme. (Basically stores an object to global map).
So, yeah I know that this will bundle all themes to output, I'm not sure that this is a problem though.
The bundler can't pick up opaque dynamic requires though.
I think it would be better to just state in readme to include themes client is want's to use in there bundler, as otherwise we have two options:
Do what I have done currently. But, even if user is using just Theme
type (no build in themes are sued), then Theme
module will be bundled in output and I think, it will contain unused build in themes, which we don't want.
Do as Maxim suggested, But bundlers will not be able to determine what should be included in output and clients might need to explicitly add theme pathes to there bundler configuration.
Do you agree, or am I missing something?
Ok, I think this is good to go. BTW, we can also use one module per theme. This way if user import theme it's require
d. But I think this is a matter of different pr.
Chart.init
to also takeTheme
as argumentregisterTheme
action