yapplabs / ember-wormhole

Render a child view somewhere else in the DOM.
MIT License
284 stars 68 forks source link

[Feature] Destination component which fires up an action when wormhole is mounted #44

Closed pavloo closed 8 years ago

pavloo commented 8 years ago

I have a use case, when I need to have some way of notifying context when wormhole is mounted into destination, eg

{{destination elementId="destination_id" action="wormholeMounted"}}
{{#ember-wormhole to="destination_id"}}
Content
{{/ember-wormhole}}

So when wormhole's content is inserted into {{destination, action wormholeMounted is fired. I already implemented this using MutationObserver in my app. Do you think it might be useful having this feature as a part of this addon? If yes, I will issue a PR. Thanks.

chrislopresto commented 8 years ago

Generally speaking we seek to avoid inferring application state from DOM. Could you provide more details? I'm curious as to why you couldn't extend from ember-wormhole and add additional logic in didInsertElement.

I imagine something along these lines would work:

import EmberWormhole from 'ember-wormhole/components/ember-wormhole';

export default EmberWormhole.extend({
  didInsertElement() {
    this._super(...arguments);
    // Send your context notification here
  }
});
pavloo commented 8 years ago

@chrislopresto yeah, it will work out. I over-engineered this thing. The issue can be closed. Thanks.

chrislopresto commented 8 years ago

:+1: