Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat(core): type checking for mods in withBemMod #463

wants to merge 2 commits into from

Conversation

belozer
Copy link
Member

@belozer belozer commented Aug 9, 2019

resolve #458

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];
Copy link
Member Author

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;

packages/core/core.tsx Outdated Show resolved Hide resolved
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);
Copy link
Member Author

Choose a reason for hiding this comment

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

Здесь нужны пробелы? <{ theme?: 'normal' }>

@belozer belozer changed the title feat(core): required mods from interface feat(core): type check for mods in withBemMod Aug 9, 2019
@belozer belozer changed the title feat(core): type check for mods in withBemMod feat(core): type checking for mods in withBemMod Aug 9, 2019
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.

@bem-react/core Proposal withBemMod with type check for mod
2 participants