Guest User

Untitled

a guest
Jun 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. 'use strict';
  2.  
  3. // Creates an array of truthy elements
  4. const joinTruthy = (glue, ...args) => args.filter(arg => arg).join(glue);
  5.  
  6. // Simple bem function
  7. export const bemUnbound = (blockName, elementName, options = {}) => [
  8. joinTruthy('__', blockName, elementName),
  9. ...Object
  10. .entries(options)
  11. .reduce(
  12. (classes, [key, enabled]) => enabled
  13. ? [
  14. ...classes,
  15. [joinTruthy('__', blockName, elementName), key].join('--')
  16. ]
  17. : classes, []
  18. )
  19. ].join(' ');
  20.  
  21. // The bem function which takes BLOCK_CLASS from the prototype
  22. export const bem = function (elementName, options) {
  23. return bemUnbound(this.BLOCK_CLASS, elementName, options);
  24. }
  25.  
  26.  
  27. // Decorator function
  28. export const EnableBem = (blockClass) =>
  29. (target) => {
  30. target.prototype.BLOCK_CLASS = blockClass;
  31. target.prototype.bem = bem;
  32. }
Add Comment
Please, Sign In to add comment