ember-script icon indicating copy to clipboard operation
ember-script copied to clipboard

hyphen in computed property declaration

Open heartsentwined opened this issue 11 years ago • 1 comments

This throws an unexpected token error at the 2nd and 3rd hyphens (-):

class App.FooController extends Em.ObjectController
  needs: ['bar-baz']

  +computed controllers.bar-baz.someOtherAttr # error here
  someAttr: ->
    @controllers.bar-baz.someOtherAttr # and here

even though they are perfectly valid when declared in the full syntax:

class App.FooController extends Em.ObjectController
  needs: ['bar-baz']

  someAttr: (->
    @controllers.get('bar-baz').someOtherAttr
  ).property('controllers.bar-baz.someOtherAttr')

heartsentwined avatar Aug 20 '13 07:08 heartsentwined

As for what the heck I'm meddling around with hyphens, it's the confusion from naming conventions.

The issue over at stefanpenner/ember-app-kit#74 seems to suggest that template names are to be named in dasherized style. The official docs also suggest data-template-name="a-template". Going further, I cannot find docs on what a corresponding route should be named, but so far I have only had success with a full set of routes, controllers, views, and templates, all named in dasherized style (I'm on a Rails-Sprockets stack):

App.Router.map ->
  @route 'bar-baz'

# template at templates/bar-baz.emblem (or .hbs - no difference)
# view at views/bar-baz.em
# controller at controllers/bar-baz.em

And that brings us back to the reference in the needs syntax in controllers. Declaring it camel-case style does work:

class App.FooController extends Em.ObjectController
  needs: ['barBaz']

  +computed controllers.barBaz.someOtherAttr
  someAttr: ->
    @controllers.barBaz.someOtherAttr

but as per the issues referenced above, perhaps these should parallel the requirement for view names and/or suggested template names?

P.S. Writing up to here, I have a feeling that this might be an ember-level issue after all; but then, if it a dasherized version is valid, then perhaps ember-script should allow it too?

heartsentwined avatar Aug 20 '13 07:08 heartsentwined