Skip to content

Add registerHooks method to Component decorator #46

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

Merged
merged 5 commits into from
Dec 17, 2016
Merged

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Dec 17, 2016

This feature allows us to register additional hooks for class components like Vue Router's beforeRouteEnter.

Close #38

@ktsn ktsn self-assigned this Dec 17, 2016
}

const Component: ComponentDecorator = function <V extends VueClass>(
options: Vue.ComponentOptions<any> | V

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace any with Vue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed.

if (typeof options === 'function') {
return componentFactory(options)
}
return function (Component: V) {
return componentFactory(Component, options)
}
} as any

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use namespace trick to bypass type assertion. Here is an example https://github.com/HerringtonDarkholme/av-ts/blob/master/src/core.ts#L173

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's nice trick, thanks!

Copy link
Member

@HerringtonDarkholme HerringtonDarkholme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me 😄

@ktsn
Copy link
Member Author

ktsn commented Dec 17, 2016

Any other comments?

@HerringtonDarkholme
Copy link
Member

LGTM 👍

@ktsn ktsn merged commit 543a2da into master Dec 17, 2016
@ktsn ktsn deleted the register-hooks branch December 17, 2016 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants