-
Notifications
You must be signed in to change notification settings - Fork 38
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
Added @:wrap support #102
Added @:wrap support #102
Conversation
|
||
static public function buildComponent(inClass:ClassType, fields:Array<Field>):Array<Field> | ||
{ | ||
if (inClass.meta.has(WRAPPED_META)) return fields; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool, but is it possible for multiple builds to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With compilation server, if the component (or its meta) is modified it looses all macro-generated meta and its build macros are re-run.
Edit: as for the usefulness of this check, the macro can be called multiple times if there are onAfterGenerate
(I think it is this one) handlers triggering another build.
HOC... Now we are talking... |
@zabojad: btw, atm you can use HOCs like this: @:jsxStatic('connectedWithIntl')
class MyComponent extends ReactComponentOfProps<Props> {
public static var connectedWithIntl = ReactRedux.connect(mapState)(injectIntl(MyComponent));
static function mapState(state:AppState, ownProps:OwnProps) {
// ...
}
// ...
} And call your component with jsx('<$MyComponent />') |
Thanks for that - we need to document it a bit now. Also worth noting that it won't work in dynamic scenarios as |
@kLabz thank you, it trully is awesome! It also needs to be documented clearly in the |
If anyone's interested, I have improved and documented I would add the docs here (like I am working on making this fork "mergeable" in a not-so-far future though, since I definitely want these contributions to come here at the end. And I will keep creating PRs for features/documentations that are compatible with current haxe-react. |
Use the power of
@:jsxStatic
to wrap a component with multiple wrappers/HOCs: redux'sconnect
, i18n with intl, react-router'swithRouter
, etc. with a simple meta.To wrap a component with a single wrapper:
You can also combine wrappers with multiple metas,
@:wrap
instructions' order will be respected (the first one will be the entry point, and the last one will provide the final props to the component):Will generate the equivalent of
MyComponentWithWrappers = ReactRouter.withRouter(ReactIntl.injectIntl(MyComponent))