This issue was originally filed by kevincox....@gmail.com
This was originality posed as a question on stack overflow http://stackoverflow.com/questions/11128476/how-can-i-lasily-dynamicaly-load-classes-in-dart/11128713
A quick summary is that it would be useful to provide a method for dynamically loading classes so that you did not have the up-front loading cost and to prevent the cost if you don't use those sections at all.
Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.
Changed the title to: "Provide a Method to Dynamicaly Load Classes".
This comment was originally written by email@example.com
Additionally for cases where you don't know the classes you need when you're writing the code -- for instance, a plugin system for an application, or third-party database drivers for a generic database layer (like JDBC, not that I'm suggesting that as a model for your application), or a test framework driver, or a reflection-based static analysis tool...
There's a question of what you want to get back when you ask to include something at runtime. Probably some reflection object, so you can find what interests you.
This comment was originally written by kevincox...@gmail.com
That would be even better.
We are looking at these issues.
Added Accepted label.
This comment was originally written by thesain...@gmail.com
We are well aware of this issue and intend to provide a workable answer. I'm marking this M3 tentatively.
Set owner to @gbracha.
Added this to the M3 milestone.
Issue #4307 has been merged into this issue.
This comment was originally written by daniel.sch...@gmail.com
Use isolates, mirrors and primitive remote method call serialization as workaround to dynamically load dart scripts into the vm. See a proof-of-concept at (plugin system): https://github.com/danschubert/dart-plugin-isolate
This comment was originally written by @seaneagan
My use case is dynamically loading code which is dependent upon the user's locale.
In particular the CLDR plural rules (http://unicode.org/reports/tr35/#Language_Plural_Rules) are naturally represented as Dart code. Otherwise one would need to include a plural rules parser on the client (bloating the code), and the AST returned from the parser would need to be traversed each time a plural category operation is invoked (too slow). In http://pub.dartlang.org/packages/intlx I generate Dart code for each locale, but as of now the generated code has to be loaded statically at compile time, so in order to support multiple locales in their application, one has to generate a different entry point for their app for each locale, and then load the correct entry point at runtime based on the detected user locale such as via the HTTP Accept-Language header. That works in many cases, but in other cases it would be more convenient to have a single entry point, and load the locale-specific code dynamically after the user's locale is detected.
Isolates don't work because I want to call the dynamic code synchronously.
Removed this from the M3 milestone.
Added this to the M4 milestone.
The comments above cover various use cases. The initial one is deferred loading, to avoid massive downloads when some code is needed only later, or perhaps only needed in some situations. We now have a mechanism for this.
There was also a request for more general form of dynamic loading, where the code being loaded is not known statically. This will require the ability advanced capabilities like mirror builders. This should be a separate issue.
This bug was originally for deferred loading, and that has been addressed.
Added Done label.