0

I'm having trouble getting consistent behavior from a conditional class binding in an Emblem template. The template is for a task list and the relevant snippet looks like this:

each task in content
  tr.task class=task.completed:complete
    td
      a.completion{ action toggleTask task}
        if task.completed
          | ✔
        else
          span.larger ☐

So the idea here is that, if the task is complete, the whole table row should have a "complete" CSS class applied. And a little farther down, if the task is complete, it shows a check mark instead of an empty checkbox. (This all depends on evaluating task.completed, which is defined as a boolean property on the Task model.)

Everything works fine when you navigate to the relevant route (tasks.index) from elsewhere in the application. But when you load this route directly or reload the page, the class binding isn't evaluated, while the conditional branch a little lower down still works just fine.

I'm wondering if this is an issue with asynchronous model loading, the difference between entering a route via linkTo vs via page loading in Ember, or just weirdness in emblem/handlebars template evaluation? It seems like the problem is that, in the broken case, my class binding isn't being correctly re-evaluated after the model finishes loading.

For reference, my route definitions read as follows:

App.TasksRoute = Ember.Route.extend
  setupController: (controller, model) ->
    @controllerFor('application').set 'currentRoute', 'tasks'
    @controller.set 'content', model

App.TasksIndexRoute = App.TasksRoute.extend
  model: (params) ->
    App.Task.find()

Has anyone else seen this issue?

  • I doubt this is an Emblem thing, but I could be wrong. Perhaps you could output something like `p = task.completed` right before the `tr` to see if that has the correct value? – Alexander Wallace Matchneer Jun 19 '13 at 13:20
  • Hi, thanks for the thought! The thing is that the conditional branch a little farther (if task.completed) along always works out perfectly, but it takes a visible moment for the rendering to complete. It seems to me that on page load, the task list is (of course) initially empty, and then when it gets populated, the conditional gets correctly executed, but the class binding for some reason isn't re-evaluated. – decasia Jun 27 '13 at 14:38
  • Update: I'm starting to think that this has to do with how undefined variables get evaluated in templates. If you define a computed variable imprecisely (eg, by making it depend on content.@each instead of content.@each.someproperty), the computed property may not get re-evaluated each time you render a template, depending on how you enter the route in question. Will investigate further and post something more definitive. :) – decasia Jun 27 '13 at 20:18
  • On second thought, I'm thinking that the problem here was this: https://github.com/machty/emblem.js/issues/78 – decasia Jul 18 '13 at 15:05

0 Answers0