Ember mixins - is this a good way to achieve 'dynamic' layout


#1

So, I posted this question on SO already, but I think it is maybe better suited for a discussion, rather than being a ‘concrete, answerable question’. C/P from SO:

What I’m trying to achieve:

The app has a few “main sections”, such as top panel, sidebar, and of course content. I would like to have a per-route ‘configuration’ which of those are shown (content is always present), with most routes having same, default, layout.

My solution:

  • Application template binds each section’s visibility to relevant ApplicationController property
  • I have a LayoutMixin which, upon entering the route, gets the route’s layoutSettings property, and updates the ApplicationController properties accordingly
  • When leaving the route, mixin reverts back the previous state

Minimalistic example: http://emberjs.jsbin.com/fidoquhira/2/edit?html,css,js,output

The approach works, and I quite like the concept of using mixin + ‘config data’ to make things happen ‘automagically’ (I’m also doing a similar thing for breadcrumbs), but am kinda worried I’m reducing clarity of what is going on, or that I’m not seeing something that may blow up at some later point.

Is this “the Ember way” of doing things?

Additionally: how to write unit tests for such mixin?

Link to SO question: http://stackoverflow.com/questions/26759931/ember-mixins-is-this-a-good-way-to-achieve-dynamic-layout

Apologies if this is inapropriate question.


#2

Answered via Stack Overflow.