Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Created March 30, 2017 20:02
Show Gist options
  • Select an option

  • Save marcoslhc/44456763617890c7b72cae6162bf4269 to your computer and use it in GitHub Desktop.

Select an option

Save marcoslhc/44456763617890c7b72cae6162bf4269 to your computer and use it in GitHub Desktop.
ClassList.prototype.concat = function (otherList) {
return ClassList.of(this.getClasses().concat(otherList.getClasses()));
}
// We check if it's a value we can work on. There are some other
// checks we need to make, but this is not the place to do it
ClassList.prototype.addClass = function (classes) {
const classesToAdd = Array.isArray(classes) ? classes
: [classes];
return ClassList.of(this.getClasses()).concat(ClassList.of(classesToAdd));
}
ClassList.prototype.removeClass = function (className) {
coonst predicate = (currentClass) => !== className;
return ClassList.of(this.getClasses()).filter(predicate)
}
ClassList.prototype.getString = function () {
return this.getClasses.join(' ');
}
const cl1 = ClassList.of(['btn'])
const cl2 = ClassList.of(['btn-default']);
const cl3 = ClassList.of(['btn-solarized', 'btn-default-solarized']);
const cl4 = cl1.concat(cl2).concat(cl3);
cl4.getString();
"btn btn-default btn-solarized btn-default-solarized"
cl4.addClass('btn-disabled').removeClass('btn-default').getString();
//"btn btn-solarized btn-default-solarized btn-disabled";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment