Skip to content

Instantly share code, notes, and snippets.

@Nopik
Last active December 10, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Nopik/4484175 to your computer and use it in GitHub Desktop.
Save Nopik/4484175 to your computer and use it in GitHub Desktop.
In controller:
App.DashboardController = Ember.Controller.extend
workspaces: []
currentWorkspace: null //set by /workspace/:id route
fetch: ->
//ajax load workspaces
In old router:
connectOutlets: ->
controller.connectOutlet 'main', 'workspaces', controller.workspaces
DashboardView:
{{outlet main}}
WorkspacesController is ArrayController, containing all workspaces
WorkspacesView template:
{{each controller itemViewClass="WorkspaceView"}}
Workspace view template:
<div {{bindAttr class="this.active"}}>Some content for single workspace</div>
Now, the workspace model, in old router:
Workspace = Ember.Object.extend
active: ->
App.router.get('dashboardController.currentWorkspace.id') == this.id
If '/' url is selected, list of workspaces is shown, none of them is active.
If '/workspace/:id' url is selected, list of workspaces is displayed, one of
them with different color, and content of that workspace is bound to one of the outlets.
In model view:
{{#if active}}
Content for 'active' model
{{/if}}
{{#unless active}}
Content for 'inactive' model
{{/unless}}
So, because of there is no {{#if a == b}} construct, I need to have this whole 'active' and 'currentWorkspace' mess.
That mess require that either model or view (depending where 'active' property is defined) has access to controller.
Is there any better solution?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment