New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for "reviving" DartObject
#178
Comments
I am not 100% sure about the We probably also want to probably add a base class, something similar to this: abstract RevivableBase<T> {
String toCodeString();
T toInstance();
} |
I mostly agree - except the |
I'm OK with the progress here so far. |
Hi guys, so what's the current api to get the value of a enum using constantReader ? |
is their a toInstance ? |
I don't think we have one. We could review a contribution adding an API to
No, it's not feasible to implement since it depends on statically importing the class that needs to be constructed. Most likely the best we can do is something like One concern is we can't statically know that |
Can dart allow us to bound generic type? |
Currently I'm doing this like that :
|
Hey all, I'm trying to take I tried this with no luck |
You can write code to handle this. See |
@kevmoo any reason why this hasn't been contributed to |
@lukepighetti – time/priority Doing it for simple things is easy, but you fall off a cliff pretty quick. PR welcome! |
@kevmoo I don't feel qualified to contribute your source to a package like source_gen. I don't even know if that's the appropriate location for that utility method. |
One of the hardest and most brittle parts of the AngularDart compiler...
Basically, we need to go from a computed
DartObject
to some sort of model class that enables code generation of an identical object. Here are some simple (trivial) examples that are solvable withConstantReader
today:String
int
/double
bool
null
List<...>
orMap<...>
of these types, recursivelyHowever, it's much harder with classes and enums. Consider these:
const Duration(seconds: 5)
const SomeClass._privateConstructor()
Enum.someValue
We could do this with
ConstantReader
, if we add a few more methods:We could also do error handling, i.e., a flag for checking if it is revivable (visible):
This isn't a perfect API, but it is probably better for some of this to live in
source_gen
(and have closer watch by the ecosystem team and analysis team) than buried in the AngularDart compiler./cc @jakemac53 @alorenzen @kevmoo
The text was updated successfully, but these errors were encountered: