Created
March 30, 2017 20:02
-
-
Save marcoslhc/44456763617890c7b72cae6162bf4269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(' '); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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