miguelcobain / ember-composability-tools

ember-composability-tools - Helpers for building a somewhat different kind of components.
MIT License
39 stars 18 forks source link

nearestOfType deprecated? #3

Closed niamleeson closed 6 years ago

niamleeson commented 7 years ago

According to Ember 2.9.1 API documentation, nearestOfType has been deprecated. Should it be changed?

miguelcobain commented 7 years ago

This is indeed a problem. However, this is solved by using contextual components. You should yield child components with parentComponent=this.

niamleeson commented 7 years ago

Here's what my app setup looks like:

map-component
    - component.js
    - template.hbs    ---> Here, {{#extended-leaflet-component}}  {{center-marker}}  {{/extended-leaflet-component}}

extended-leaflet-component 
    - component.js
    - (no template)

center-marker
    - component.js
    - template.hbs

In map-component's template, I am rendering extended-leaflet-component and I only have the tile-layer as the only component from ember-leaflet. Other than tile-layer the only contextual component is a simple Ember component (center-marker) that is just a marker image. The marker image just sits in the center of the map all the time so that it works like how Uber's app works.

The center-marker is not mixed in with ChildMixin nor does it have parentComponent=this passed to it. Triggering change to the center-marker causes ember-leaflet to initialize the map again, which of course throws an error because the map already exists. The only fix I have so far is doing the following to the extended-leaflet-component:

didInsertParent() {
    if(Ember.isNone(this._layer)) {
      this._layer = this.createLayer();
      this._addObservers();
      this._addEventListeners();
      if ( this.get('parentComponent') ) {
        this.addToContainer();
      }
      this.didCreateLayer();
    }
  }

Any thoughts on what needs to be done to not have this block of code in the parentComponent?

miguelcobain commented 7 years ago

In what ember version does that happen?

niamleeson commented 7 years ago

Currently, I am using Ember 2.9.0

edborden commented 7 years ago

@miguelcobain Can you provide an example of the parentComponent=this usage?

BennyAlex commented 7 years ago

@miguelcobain Should I always use parentComponent=this? And does it have any other effects? Can you extend the readme to this topic, please?

miguelcobain commented 7 years ago

@BennyAlex yes, you should. No other effects, it is a drop-in replacement. By doing that you're basically overriding a computed property that calls nearestOfType.

acorncom commented 7 years ago

Double-checked with Robert Jackson about whether this property was deprecated in error and he thought that nearestOfType will probably stay deprecated. I think this issue can probably be closed at this point ...