Last active
December 10, 2015 19:48
-
-
Save Nopik/4484175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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