Comments (4)
There isn't a way to implicitly search all transitive libraries and generate code based on what you see.
This is generally just a bad thing to do for performance reasons. It means that a single macro will have O(n) time complexity where n is the total number of libraries in the application, and there would be a large constant multiplier to boot.
Worse than just the time to execute the macro, it will also have to re-run whenever any library changes, because it has an implicit dependency on every library in the program.
We could try to design an alternative way to do this, which is more "modular", but it is challenging to design the semantics of it, and we aren't looking into it in earnest at this time. Essentially though, you would want the @Route
macro in this case to simply emit some piece of data, which is globally readable from some other macro. And that higher level macro which reads all the global data emitted by all the @Route
macros would only re-run when that data changes (so only if a new @Route
was added, or one was altered). And the individual @Route
macros only re-ran if the library they are applied inside of changes (or possibly even more granular than that, but it might not be necessary).
For this to be supported today though, you need some explicit piece of code referencing all the relevant types, to help you generate the AppRoutes
class, something like this:
@GenerateRoutes([HomeScreen, LoginScreen])
class AppRoutes {}
from language.
I am going to close this as not planned for now, as we don't currently have any concrete plan to support it.
from language.
As far as I understand, we don't need to depend on all libraries. All we need here is to have some kind of API method that could return all classes with metadata (in this case, Route). And then it seems it would be possible to generate the method.
@GenerateRoutes([HomeScreen, LoginScreen])
class AppRoutes {}
I thought about code like this. If there is no other way, even this code would be OK. But in case of many screen classes it's still not that the best option from user point of view. Macros should help us to get rid of boilerplate, but the code like this is exactly with what macros should've help.
It is nice that we would have macros at all, but they are seem so limited right now.
Nevertheless, thanks for your reply!
from language.
All we need here is to have some kind of API method that could return all classes with metadata (in this case, Route)
The problem is that API has to visit all libraries to give you an answer. It has to look at every class in every library, and check for matching metadata. A naive implementation ends up re-running the entire query across the entire program, any time any change to any library is made.
Yes, this could be specialized in some way, such that when a single library changed we know all the whole-app queries which were asked, run those queries only on that library, and compare the old results against the new results, and only re-run the macros whose queries were affected. But, this would be a lot of work to design and implement in any sort of general purpose manner, not to mention extra memory to hold onto these query results indefinitely, etc. It has to be very carefully thought out to work well.
from language.
Related Issues (20)
- Consider moving _macros/macros into _fe_analyzer_shared for breaking changes HOT 11
- Static type metadata guided shorthands and features HOT 4
- No macro.TypeDeclarationImpl for `dynamic` HOT 4
- Adoption of functional programming in the Dart language HOT 2
- Enhancing `library` and `part of` Declarations in Dart HOT 1
- Create the type `Monad` HOT 4
- Allow `import` and `part` to have wildcard path to import every lib in specific directory HOT 1
- Adding conditional imports/parts with macros. HOT 2
- Consider changing the context for the operand of `throw` to `Object`. HOT 3
- Allow statically known class fields to be used in switch statements HOT 4
- could support static extension? HOT 2
- Macro - Augment class with generic HOT 7
- Macro annotation information in yaml files next steps HOT 2
- Network paths don't work anymore with version 3.4.0 HOT 2
- "Merge to source" for macros that only need Phase 3 HOT 21
- Follow up on "spawn isolate from kernel blob" implementation
- Allow pattern `case` conditions in `while` statements. HOT 2
- Unable to call super method on an object. HOT 2
- Add syntactic sugar for package imports HOT 2
- Allow recursive extension type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from language.