-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat(core): type checking for mods in withBemMod #463
base: master
Are you sure you want to change the base?
Conversation
return function WithBemMod<K extends IClassNameProps = {}>(WrappedComponent: ComponentType<T & K>) { | ||
// Use cache to prevent create new component when props are changed. | ||
let ModifiedComponent: ComponentType<any>; | ||
|
||
return function BemMod(props: T & K) { | ||
const entity = cn(blockName); | ||
const isMatched = (key: string) => (props as Dictionary)[key] === mod[key]; | ||
const isStarMatched = (key: string) => mod[key] === '*' && Boolean((props as Dictionary)[key]); | ||
const isMatched = (key: string) => (props as Dictionary)[key] === (mod as Dictionary)[key]; |
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.
Чёт мне не нравится постоянное дублирование props as Dictionary, mod as Dictionary
Это можно "профиксить" так
const _props = props as Dictionary;
const _mod = mod as Dictionary;
expect(getClassNameFromSelector(<WBCM className="Additional" />)) | ||
.eq('Presenter Additional'); | ||
}); | ||
|
||
it('should add modifier class for matched prop', () => { | ||
const Enhanced1 = withBemMod<IPresenterProps>(presenter(), { theme: 'normal' })(Presenter); | ||
const Enhanced2 = withBemMod<IPresenterProps>(presenter(), { view: 'default' })(Enhanced1); | ||
const Enhanced1 = withBemMod<{theme?: 'normal'}>(presenter(), { theme: 'normal' })(Presenter); |
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.
Здесь нужны пробелы? <{ theme?: 'normal' }>
resolve #458