-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add flag to disable reflection #2710
Conversation
@alfonsogarciacaro, would it be possible to also have an attribute that we could selectively apply on types? Sort of use at your own risk thing? Very often you do need reflection in a part of the application (serializing data contract types in Remoting for instance) but not in another (Elmish models, messages). For type Msg =
| TabClicked
| UpdatePasswordClicked
| UpdateProfileClicked
| UpdateAccountClicked I get import { Union } from "fable-library/Types.js";
import { union_type } from "fable-library/Reflection.js";
export class Msg extends Union {
constructor(tag, ...fields) {
super();
this.tag = (tag | 0);
this.fields = fields;
}
cases() {
return ["TabClicked", "UpdatePasswordClicked", "UpdateProfileClicked", "UpdateAccountClicked"];
}
}
export function Msg$reflection() {
return union_type("Test.Msg", [], Msg, () => [[], [], [], []]);
} and none of that is treeshaken by Terser. What I would like is import { Union } from "fable-library/Types.js";
export class Msg extends Union {
constructor(tag, ...fields) {
super();
this.tag = (tag | 0);
this.fields = fields;
}
} (When no case has any fields, perhaps |
Actually, looking at that desired output, there's no need to emit anything since you could just use the basic |
I add completely missed that you added this flag @alfonsogarciacaro. 😅 @kerams I just want to point that in case you are using |
@MangelMaxime, sure but in that case you can conditionally compile the attribute just for production :). |
@kerams Yes sure, just wanted to point it out in case you encounter this bug in the future. Because, I don't know what error / warning would be emitted by Fable in such a case and if it would be user friendly or not. |
If you use it in your code and something breaks, it's your problem (Don't touch the attribute unless you know what you're doing, much like |
Thanks @kerams. I think it makes sense to have an attribute to regulate this behavior on a per-type basis. Although we need to be careful because adding more specific behavior increases complexity and sometimes it doesn't actually bring the benefits we expect. Some notes:
|
See #2489 (comment)