How to bind class names with ember-cli


#1

Is there a way to bind names to classes defined in ES6 syntax? For example all model instances are reported as (subclass of DS.Model) in the console.


#2

Should be as simple as providing a toString to your class:

export default DS.Model.extend({
  toString: function() {
    'MyAwesomeUserClass'
  }
});

(can’t test at the moment though)


#3

@rwjblue Thanks–so would it be correct to say this has nothing to do specifically with ember-cli but rather the transpiler? If so I wonder if some magic could be done there to auto-generate toString() functions.


#4

No, it is definitely not a transpiler concern.

It is possible that the either the container or resolver could attach a toString (since it knows what you used to look the model up), but I am not completely sold on that.


#5

That doesn’t sound like a bad idea at all, maybe hook in to https://github.com/aexmachina/ember-devtools and/or in development ENV only?

It’d be a big time-saver to be able to have a more useful inspect per class, dumping out interesting properties, like attribute values for models, etc.


#6

Thanks for the lead @rwjblue. It looks like this is precisely what’s already done for the other types (lookupDescription, makeToString, etc.). Not sure why not for models.


#7

You have to have EmberENV.MODEL_FACTORY_INJECTIONS enabled for it to work with models.


#8

Confirmed that works for 0.0.37, thanks.