Tristan - What do you mean by lazy import?
# javascript
n
Tristan - What do you mean by lazy import?
k
Probably that the actual import only happens when something from it is used? No idea what it would be useful for though.
n
So the lazy import is the equivalent of a included Kotlin import that is marked by the IDE as a warning when unused in a Kotlin source file, but is no longer a warning when it is used. 😆
u
i guess to reduce parsing time during page load/app start
t
It's useful when you build a SPA, but you don't want to download everything. Maybe the user will not go through all the pages, so we just take what we need and download the missing part of the code when you need it.
k
Well you can emulate it, create a wrapper class that only fetches the requited files when the relevant functions are first called.
t
I don't get it. How Kotlin's compiler will know that it should not bundle everything into one file?
k
Ah right, I thought you were talking about importing a Javascript library. An option would be to separate the code into multiple projects, but that's going to need a bunch of boilerplate.
I don't think it's supported right now.
b
Right, we don’t have a builtin feature for that, but you can achieve it by writing
require
manually where you need it.
Also, I believe, it can be done by linkers, like webpack.
k
Can you use require within a single project though?
b
@karelpeeters You can’t use this trick inside one Kotlin module.
t
If kotlin plan to compile into webassembly, it will be something to integrate anyway http://webassembly.org/docs/dynamic-linking/ Maybe introduce a new keyword?
n
Far better NOT to have a new keyword introduced into Kotlin unless it is really necessary!
t
Or just a decorator, Dart is thinking about it. https://github.com/dart-lang/sdk/blob/master/docs/newsletter/20170804.md
b
We are going to support JS Decorators