Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- // Creates an array of truthy elements
- const joinTruthy = (glue, ...args) => args.filter(arg => arg).join(glue);
- // Simple bem function
- export const bemUnbound = (blockName, elementName, options = {}) => [
- joinTruthy('__', blockName, elementName),
- ...Object
- .entries(options)
- .reduce(
- (classes, [key, enabled]) => enabled
- ? [
- ...classes,
- [joinTruthy('__', blockName, elementName), key].join('--')
- ]
- : classes, []
- )
- ].join(' ');
- // The bem function which takes BLOCK_CLASS from the prototype
- export const bem = function (elementName, options) {
- return bemUnbound(this.BLOCK_CLASS, elementName, options);
- }
- // Decorator function
- export const EnableBem = (blockClass) =>
- (target) => {
- target.prototype.BLOCK_CLASS = blockClass;
- target.prototype.bem = bem;
- }
Add Comment
Please, Sign In to add comment