In UNIX way, each view should solve single task. This is good idea, but sometimes we need to mix logic of different views on same page. Filter, sort, paginate, or, for example, add comment on product page. In this article I'll show how we can mix such multiple views.
We can write views as decorators.
Simplified filtration can look like this:
This is simple and straightforward, but in order to add some tricky pagination, we have to copy entire view and add more code to it.
Instead, we can create decorator like this:
Assuming, that we have similar decorators, sorted
и paginated
, we can easily combine them:
Or even like this, in lisp style: