miguelcobain / ember-composability-tools

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

`didInsertParent` called before `element` and `.$()` become available #16

Closed lolmaus closed 2 years ago

lolmaus commented 6 years ago

Reproduction:

cd yuidork
git checkout gen-1-1
bower i
yarn
ember s

Visit this URL: http://localhost:4200/#/emberjs/ember.js/master/modules/@ember*application

Then click Application in the Classes section in the leftmost menu. The app will crash because it tries to access a property on this.$() from didInsertParent, but this.$() returns undefined.

The cause of the problem is visible in the debugger:

  1. Child mixin calls initChild on init.

    https://github.com/miguelcobain/ember-composability-tools/blob/v0.0.9/addon/mixins/child.js#L17

  2. Child's initChild calls registerWithParent.

    https://github.com/miguelcobain/ember-composability-tools/blob/v0.0.9/addon/mixins/child.js#L21

  3. Child's registerWithParent calls registerChild on parent.

    https://github.com/miguelcobain/ember-composability-tools/blob/v0.0.9/addon/mixins/child.js#L54

  4. Parent's registerChild calls didInsertParent on child.

    https://github.com/miguelcobain/ember-composability-tools/blob/v0.0.9/addon/mixins/parent.js#L77

Since this all started on child's init, child's element and $() are unavailable.

Duder-onomy commented 6 years ago

@lolmaus Does #11 fix this for you? I have a feeling it might.

miguelcobain commented 2 years ago

Closed due to https://github.com/miguelcobain/ember-composability-tools/pull/11#issuecomment-943963569