Separate Concerns, Reduce Mocking
We want the list of tasks to appear in the ascending order of year, month, day, and name. That calls for a sort operation, but where to put that? We need to make a careful decision about thisâkeep modularity and the single responsibility principle in mind.
Find the Right Place
AngularJS makes it very easy to sort data, right in the HTML page. Hereâs one possible solution that could go into the HTML page weâll design eventually:
â | <tr ng-repeat=â"task in controller.tasks | orderBy: year"â>...</tr> |
Thatâs sleek, orâ¦is it sick?
At first sight that looks sleekâconcise, declarative, elegant. But then, the sorting logic would be in the HTML page. We want to sort based on a particular precedence now ...
Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.