Coder Social home page Coder Social logo

Comments (4)

jakemac53 avatar jakemac53 commented on June 24, 2024

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.

jakemac53 avatar jakemac53 commented on June 24, 2024

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.

ChessMax avatar ChessMax commented on June 24, 2024

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.

jakemac53 avatar jakemac53 commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.