I'd like to add view components to the 1.0 roadmap. This idea has been floating around in my head for some time and I think it can bring a lot of value if implemented correctly.
Often a view is rendered in many places throughout an app. Take, for example, a nav view at the top of a layout. Right now you have to call the logic that renders the nav from each route (often via an
after hook or via a mutator). This couples the view and route by forcing the route to know something about the view that will be presented. It also prevents a front-end dev from using the nav in some other view without hooking up the backend code for rendering it.
Each view component would consist of: 1) the view and 2) rendering logic. When Pakyow presented a view, it would check for the presence of any components in the view being presented. If found, it would invoke the logic required to render that component. A component could be reused in any view just by including the component (components and partials would be roughly the same; the difference being that a component is a partial with rendering logic defined).
Here's how you might include a component into a view:
<!-- @include some_component -->
And this is how you might define a component:
Pakyow::App.component :some_component do |view|
# rendering logic goes here
One note on accessing state. The component logic would be called in a context that has access to the underlying request, params, and session state. This is pretty much necessary to do anything useful.
Let me know your thoughts!