Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Provide a Method to Dynamicaly Load Classes #3819

Closed
DartBot opened this Issue · 11 comments

4 participants

@DartBot
Collaborator

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.

@sethladd
Owner

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.
Changed the title to: "Provide a Method to Dynamicaly Load Classes".

@DartBot
Collaborator

This comment was originally written by dhasenan@gmail.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.

@DartBot
Collaborator

This comment was originally written by kevincox...@gmail.com


That would be even better.

@gbracha
Collaborator

We are looking at these issues.


Added Accepted label.

@DartBot
Collaborator

This comment was originally written by thesain...@gmail.com


I also want to add an important use case. Since next-gen web apps are expected to deliver desktop-like experience, probably the most important aspect are plugins. Imagine a Web-3D engine, which is definitely one of the many amazing things Dart is best suited for on paper. Almost any engine out there, and for good reasons, doesn't require you to recompile the entire beast just to add behaviour to your assets. Instead they let you hotplug scripts into the game, which could be done through a code editor in a web-page. Of course one could build a script system statically on top of Dart but let's be realistic... JavaScript is slow as it is, no need for an interpreted scripting environment on top of that. So it it really important that users can write their own scripts in Dart, and then my app maybe uses Frog to compile it to JavaScript, and now some shiny new mechanism, to instanciate the user's class.

From a language perspective Dart should be more than capable, in constrast to JavaScript, to provide a stable plugin-mechanism, since runtime code changes are not permittet.

@gbracha
Collaborator

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.

@gbracha
Collaborator

Issue #4307 has been merged into this issue.

@DartBot
Collaborator

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

@DartBot
Collaborator

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.

@anders-sandholm

Removed this from the M3 milestone.
Added this to the M4 milestone.

@gbracha
Collaborator

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.

@gbracha gbracha was assigned by DartBot
@DartBot DartBot added this to the M4 milestone
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.