Last active
August 29, 2015 14:03
-
-
Save FelixAkk/708a871755fbd4342b70 to your computer and use it in GitHub Desktop.
The cure for the disease of div-itis
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
| # Heads up to front-end developers! | |
| # $.append isn’t the only DOM insertion function! | |
| # It requires containers to append elements into. | |
| # It’s the primary source of excessive div-itis. | |
| # Abandon the practice of e.g. | |
| # @$(‘div.itself div.container div.sub-container div.collection div.comments’).append($comments) | |
| # And switch to the more semantic: | |
| @place = @$("header").after | |
| @place($body) | |
| # Wrap with $.proxy when sending out of context, e.g. | |
| super | |
| place: $.proxy(@$header.after, @$header) | |
| # So that views like collections can | |
| place(child.$el) for child in @childs | |
| # In flat DOM structures, when they should be kept flat | |
| # So next time you create a composite view ;) | |
| @$("div.message").after(@comments.$el) | |
| # Which sadly reads the other way around; after message comes comments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment