mardi 15 novembre 2016

Do ember.js class-based helpers remove observers?

I've got a simple class-based helper in ember that adds an observer to call .recompute whenever the property changes. Since there is no opportunity to call removeObserver (as there is no destroy... method on helpers), will continued use of the helper accumulate observer 'cruft' over time and cause a performance leak?

Here is the code: the helper enables grabbing a service or a property on it right in a template instead of having to put the service into the component or controller code behind the template:

export default Ember.Helper.extend({
    someService: Ember.inject.service(),
    compute: function([propName]) {
        const svc = this.get('svc');
        if (Ember.isPresent(propName)) {
            svc.addObserver(propName, this, 'recompute');
        }
        return propName ? get(svc, propName) : svc;
    },
});




Aucun commentaire:

Enregistrer un commentaire