Before I get any further; I need to thank @molily, @paulmillr, @karellm, @9elements, @moviepilot, et al for such an awesome library to build upon.
After our discussion on #202 and after hearing everyone's opinions on the matter I realized that sub-routing was much more of a beast than it had to be. It was much too complicated for the problem it was trying originally to solve.
So from that came composing. Additions are two-fold. The first of which is named regions -- in essence, providing canonical names to selectors. All views can register regions through their regions method. This is not directly related to composing however it complements it greatly as we'll see. The second and last is the ability for views to not only be instantiated and rendered by a controller, but to alternatively be composed. A composed view is instantiated and rendered only if it has not been composed before. Once a view is composed in an action; as long as all subsequent actions likewise compose it, it will not be disposed.
An example shall tell a thousand words: http://concordusapps.github.com/composer-example/
And the source to the example: https://github.com/concordusapps/composer-example
The modifications to chaplin are located at https://github.com/concordusapps/chaplin/tree/topics/composition. Layout is responsible for region management. A new module, Composer is responsible for the composition process and tracking lifetime of composed views.
Still working on the implementation (though its mostly done) and testing before I'll be ready to submit the PR.
Any concerns, ideas, comments?
Haven't had a chance to check the code, but the general idea is one we've tackled one-off in a couple of projects and I'm excited for a standardized approach.
Wow, that looks exactly what i was looking for.
Did a quick glance and I'm not sure about views creating controller instances. Feels backwards.
Dude, that’s pretty cool! 👍
Could you please open a work-in-progress pull request with changes?
btw I'm 100% in support of this feature. Let the bike-shedding commence :)
yes am on it too. try to build it directly with-in my new app :D - was looking for a solution for days. and now this! thx.
Apologies on leaving the controllers being created by the site view. Meant to change that to be subviews. You're totally right in that in seems a bit backwards.
Basic usage is as follows:
@publishEvent '!composer:compose`, ViewClass
Let me clean a few things up and I'll submit that PR shortly then. Thanks for the support.