-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conditional Configuration #126
Comments
Perhaps we need to go back to the idea of package-level meta configuration, and have this meta specified at the package level. |
Having this at the package level makes more sense to me too. |
Thanks, yeah I'm currently playing with the idea of deprecating meta in favour of package config. This was something I implemented back in December but removed.... we all make mistakes! |
agreed. meta at the pkg level is the way to go here. Also, you should use |
Here's a proposal for conditional package configuration (in combination with #141): System.config({
packages: {
'my/package': {
branches: { // branches or conditionals?
'graphics': { // this refers to the 'my/package/graphics.js' module (may or may not actually exist)
condition: 'platform', // this refers to a condition module, System.import('platform')
map: { // this is the map value depending on the default result of the condition module
'mobile': 'graphics/mobile', // use 'my/package/graphics/mobile.js'
'tablet': 'graphics/tablet' // use 'my/package/graphics/tablet.js'
// if no value is matched, we use the original module name
}
},
'some/polyfill': {
condition: './has-feature', // this is a polyfill check returning true or false. Module name is relative to package itself.
map: '@empty' // boolean, so we only map if the condition returns true, in this case to an empty module (which is always defined in the registry in SystemJS. This way the polyfill at 'my/package/some/polyfill.js' is only loaded if needed).
}
}
}
}
}); platform.js export default getPlatformType(); my/package/has-feature.js export default checkNeedsPolyfill() ? true : false; Feedback welcome. I'm pretty happy with the above. |
One of the great features of the above, is it is possible to statically analyze all the branches in the conditional tree really easily, since we know what conditions lead to what outcomes without having to execute browser code. |
Note that because this uses map config, we can conditionally map entire folders too, and not just modules. |
IMO, this is way too much magic. I think we should focus on the lower level, and let devs to build on top of that. The bit that is a no-go for me is the fact that you have to go and fetch the
that's very straight forward, and you could add as much complexity as you want if you make |
/cc @juandopazo |
I like the |
What if we allowed both The reason I value having the condition set by a module is because it makes this into a true modular configuration (something that can be stored in JSON), as opposed to something that has to be manually configured. |
I totally agree with pure JSON configuration being desirable. I see many users just defining the test module with |
You're right - typically one would build in the conditional modules necessary for my code at the top of the bundle, and then create the bundle to include modules in the tree, stopping at these conditional branches. Surely that is the ideal production situation (tracing all possible conditionals as module trees themselves), and the information is as simple as possible for this need? If performance were an issue, we could write in the conditional modules as |
Any further thoughts on conditionals or packages please let me know... I'm keen to start implementing soon. |
Perhaps we could also allow the System.config({
packages: {
'my/package': {
main: 'index',
mainBranch: {
condition: 'platform',
map: {
'ie': 'main-ie',
'safari': 'main-safari'
'firefox': 'main-firefox'
}
}
}
}
}); Perhaps we still need a better name for some of these properties? Perhaps we could simplify the entire process and only allow branching at the main entry point level? That makes sub packages a little harder though. |
I've implemented conditional configuration based roughly on these ideas at #189. feedback welcome. |
#285 is now the primary proposal. |
This is a very rough shot in the dark to spur further discussion / ideas.
The argument against conditional loading within module syntax is that it is using incompatible syntax (#9).
The argument against upfront feature detection is that it requires manual configuration to set up (#9 (comment)).
We need some way for a package to specify its target environment, and then be dynamically given the environment it needs and in a modular way. The environment could just be the global state, or a combination of globals and locals during execution.
The environment itself can be a module name.
I was considering something along the lines of:
Where this meta gets picked up by the loader, and it first ensures that the environment has promises before going further. The environment setup itself is an asynchronous function such as:
environments/promises.js:
Promises is a bad example, but that is the rough idea.
We maintain modular configuration without obscuring the syntax. And environments that don't support this modular environment configuration won't notice a difference.
The text was updated successfully, but these errors were encountered: