windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

Ember JS: observed properties on destroyed objects

Asked By: Anonymous

I’m working on a simple app which displays a list of issues of a particular repo on Github. Below is the code of IssueView which generates the html of an issue and insert to the DOM

 App.IssueView = Ember.View.extend({
   tagName: "li",
   classNames: ["sugar", "issue_wrapper"],
   templateName: "app/templates/issue",
   init: function() {
     App.LabelsController.addObserver("label", this, this.labelUpdated);
     this._super();
   },
   click: function(event) {
     var target = event.target;

     if (target.className == "title") {
       // Using bindingContext is a temporary solution to access data of this issue
       App.IssuesController.set("issue", this.bindingContext);
       App.IssuesController.set("state", "viewIssueDetails").notifyPropertyChange("state");
     }
   },
   labelUpdated: function() {
     this.labels = this.labels || this._collectLabels(),
     label = App.LabelsController.get("label").name;

     this.set("isVisible", this.labels.indexOf(label) != -1);
   },
   _collectLabels: function() {
     var labels = [];

     this.bindingContext.labels.forEach(function(label) { labels.push(label.name) });

     return labels;
   }
 })

The way I generate it is

<script type="text/x-handlebars">
  {{#view App.IssuesListView}}
    {{#each App.IssuesController}}
      {{view App.IssueView contentBinding="this"}}
    {{/each}}
  {{/view}}
</script>

The problem I had is with this line

App.LabelsController.addObserver("label", this, this.labelUpdated);

Everytime a new IssueView is generated and inserted into the DOM, I got an error “You cannot set observed properties on destroyed objects” when the ‘label’ property of LabelsController is updated. When I look into Firebug I saw that my IssueView’s state is “destroy” instead of inDOM. I wonder why that happened and what can I do to get around it?


Solution

Answered By: Anonymous

The #each helper in your template will ensure that IssueViews are created and destroyed as the collection of issues changes. You are manually adding the observer, which means you are responsible for removing the observer, too. I believe that using the observes(...) function prototype extension will handle that for you. (See http://ember-docs.herokuapp.com/symbols/Ember.Observable.html under “Observing Property Changes”).

If you want to pursue the manual route, consider moving the addObserver to didInsertElement and adding a corresponding removeObserver in willDestroyElement.

One side note: if I’m understanding what you are trying to do with this code correctly, I would consider binding to an ArrayController that handles presenting the correct set of issues based on the selected label instead of the approach you are taking.

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
Alanya escort Manavgat escort Fethiye escort Kemer escort Didim escort http://www.kadinescort.net Gaziantep escort Denizli escort Adana escort Hatay escort Aydın escort İzmir escort Ankara escort Antalya escort Bursa escort İstanbul escort Kocaeli escort Konya escort Muğla escort Malatya escort Kayseri escort Mersin escort Samsun escort Sinop escort Tekirdağ escort Eskişehir escort Yalova escort Rize escort Amasya escort Balıkesir escort Çanakkale escort Bolu escort Erzincan escort Şırnak escort Van escort Yozgat escort Zonguldak escort Afyon escort Adıyaman escort Bilecik escort Aksaray escort Ağri escort Bitlis escort Siirt escort Çorum escort Burdur escort Diyarbakir escort Edirne escort Düzce escort Erzurum escort Kırklareli escort Giresun escort Kilis escort Kars escort Karabük escort Kırıkkale escort Mardin escort Kırşehir escort Maraş escort Manisa escort Muş escort Kastamonu escort Ordu escort Nevşehir escort Sakarya escort Osmaniye escort Şanliurfa escort Sivas escort Trabzon escort Tokat escort Ardahan escort Bartın escort Karaman escort Batman escort Bayburt escort Bingöl escort Elaziğ escort Gümüşhane escort Hakkari escort Isparta escort Uşak escort Igdır escort