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
Custom import generator #40
Comments
Couldn't you also just do import * as List from '@collectable/list'
import * as Map from '@collectable/map'
export { List, Map } I'm pretty sure that rollup and webpack2 would still tree-shaking that (?) |
Yeah definitely, it's more about this: import {get as mapGet, set as mapSet, ......................................} from '@collectable/map';
import {get as listGet, set as listSet, ......................................} from '@collectable/list';
// and way more imports here vs import {Map, List} from './collections';
let list: List<string>, Map<number, string>;
// ...
list = List.empty<string>();
let list2 = List.append('a', list);
map = Map.fromArray([[0, 'a']]);
let map2 = Map.set(0, 'b', map); The latter is much easier to manage, it doesn't suffer from having to constantly organise your imports as your code evolves to use or not use a given named import, and you still get tree-shaking, because even though you've bundled a bunch of functions into a singular export, you still have control over what your application uses, without dragging in extraneous stuff that will bloat your bundle with redundant code. |
Functional imports when using multiple collections is fiddly and messy because you end up with loads of imports to manage in every source file, and you have to use aliasing a lot to account for commonalities among function names (e.g.
freeze
,get
, etc.). I've discovered that a good pattern is to create an internal collections script that imports all of the required functions and exports them as unified collection types/namespaces. It's better for this to be done by the consuming application, because you lose the ability to tree-shake unused imports, so you want to make sure you only expose the methods you're actually using.In the docs area, I want a page that lets you select all the collections and methods you want, then automatically generates a script with all of imports and exports ready to go.
Example script that would be generated:
The text was updated successfully, but these errors were encountered: