vendredi 11 mars 2016

How works Embers `toString` and how to give my Ember Objects fancy names?

I write some Ember code (an ember-cli addon) where I have custom helper Objects.

There I have some Computed Properties that return helper object instances.

For example a simple Mixin:

// my-addon/cool-mixin
import Ember from 'ember';
import CoolThing from 'my-addon/cool-thing';

export default Ember.Mixin.create({
    coolThing: Ember.computed('foo', {
        return CoolThing.create({
            foo : this.get('foo')
        });
    })
});

// my-addon/cool-thing
import Ember form 'ember';
export default Ember.Object.create({});

Now everything works fine but when I use this Mixin I always get instances of (subclass of Ember.Object), which is not nice:

import Ember form 'ember';
import CoolMixin from 'my-addon/cool-mixin';
Ember.Controller.extend(CoolMixin, {
    actions: {
        debug() {
            alert(this.get('coolThing').toString()); // here I cant something like "myAddon.CoolThing" or anything usefull
        }
    }
});

What is the best way to give my Object a fancy name? It works nice for Ember internal Objects (like ObjectProxy), but I cant find the code how they do it!

I know that if I lookup the Object with the container everything gets a fancy name, but how to get it for static imports?

So:

  1. How does Ember.ObjectProxy get its cool name?
  2. What is the best way for me to give Objects a name in my addon?



Aucun commentaire:

Enregistrer un commentaire