mardi 4 février 2020

Why is this Ember component created twice?

So really I'm just trying to decipher how Ember works here.

So I have ComponentOne. Which has propertyA (boolean) and property2 (array). If propertyA === true, the template will render and instance ComponentTwo for each member of propertyB:


  
    
  

While working with this we discovered an issue where an event handler in ComponentTwo was not running, even though we could verify the event was firing. This was happening in a situation where propertyA === true and propertyB.length === 1.

Through some judicious breakpoints and logging to the console, I was able to determine that this was happening in this sequence:

  1. an instance of ComponentTwo is created
  2. A second instance of ComponentTwo is created, using the same object for data.
  3. The first instance created in step 1 is destroyed.

The theory is that this is messing up the event handler because that handler was set in ComponentTwo.init() and removed in ComponentTwo.willDestroy(). Eventer being a singleton, it removes it for both instances of the component.

So my question is why would Ember create two instance at all? There's only one member of the array it's iterating.




Aucun commentaire:

Enregistrer un commentaire