@:jsxStatic: add field for identifying jsxStatic components#107
@:jsxStatic: add field for identifying jsxStatic components#107elsassph merged 2 commits intomassive-oss:masterfrom
@:jsxStatic: add field for identifying jsxStatic components#107Conversation
|
Why the global build macro? |
|
Because I have no other way to add a build macro to a class with |
|
Isn't |
|
No, it's supposed to be used on non-React classes to make them work like React classes in the jsx context (but without the component lifecycle). |
|
Ah... you want to solve cases where the class is never used with JSX... eh I don't like that :( but I guess there's no clean solution for that. |
src/lib/react/jsx/JsxStaticMacro.hx
Outdated
|
|
||
| static public function build():Array<Field> | ||
| { | ||
| var fields = Context.getBuildFields(); |
There was a problem hiding this comment.
We can avoid calling getBuildFields and return null if we don't need to modify the fields. What would Tink do? ;)
There was a problem hiding this comment.
I always forget about this :)
There was a problem hiding this comment.
And now the cost is almost null, it takes 0.015s on my 1.4s build.
src/lib/react/jsx/JsxStaticMacro.hx
Outdated
| { | ||
| var fields = Context.getBuildFields(); | ||
| var cls = Context.getLocalClass(); | ||
| if (cls == null) return fields; |
There was a problem hiding this comment.
Since it's a build macro called for every type, yes.
Not exactly. It doesn't change anything if the class has been used or not with jsx, it's handled there but not modified. I want to solve cases where the class is used outside JSX, whether or not it is used with JSX elsewhere in the project. This could even (not 100% about that) be built into |
Allows identification of a component as a
@:jsxStaticcomponent outside thejsx(' ... ')macro, by adding a__jsxStatic:CreateElementTypestatic field to classes with@:jsxStaticmeta.Example usage: