-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A more flexible way to append Ember.View to DOM? #587
Comments
Why not create the view in advance with bindings and just toggle is visible when the data is ready? |
As for why I'm creating the view after the XHR request, I'm dealing with a large and somewhat buggy 3rd party script: if the element is inserted but is empty, then the 3rd party script kind of craps out on didInsertElement, so I need to make sure that the object bindings in But that's just a little aside, really this issue is about me needing to prepend the Ember.View, and not wanting to cargo cult the body of |
@wagenet is right. |
An observer would fire every time the binding changes -- I just need a one-shot for the initial data load. Anyway, this issue is about me needing Ember.View.prependTo or something similar. |
|
This issue is related to #574. Should I add a |
That'd be a pretty cool thing to do. :) |
Closing in favor of #627. |
@radicaled After thinking about this more, I don't think you should be using DOM insertion anyway. This is what |
Is the purpose of EmberJS to have all HTML elements encapsulated within a JavaScript backed view? I was under the impression I could freely mix-match freestanding HTML with EmberJS-backed HTML views together freely, but this and #627 implies we're not supposed to do that. |
In general, you want one parent view for each app, though there may be exceptions. There's no harm in putting HTML into that parent view that Ember doesn't directly control, just make sure you aren't trying to control the same stuff both from Ember and from elsewhere at the same time. |
If you tell me a bit more about your app I may be able to help clarify things. |
I have a regular, garden variety CMS that is using EmberJS to drive some of the more app-like bits -- using it to control the behavior of a "media player" widget is one of the things its doing. In the context of this ticket, I needed the functionality to prepend this widget to an existing HTML structure, and be notified when the element was rendered so I could run some 3rd party JS that only worked right with visible elements. I didn't want to cargo cult the method definition of view.append everywhere I wanted to do a view.prepend or a view.after or a view.before, etc. |
@radicaled Have you seen |
@wagenet Are you proposing that I |
No. You said you depend on 3rd party JS that needs visible elements. I was suggesting you make an Ember.View with the right HTML and then trigger the 3rd party JS on |
Whoops! My bad. |
@radicaled Does this work for your case? I want to make sure you have a good solution to this. |
I think so. Just one quick question related: <div id='music-player-container'>
<!-- Need to insert App.View.PlayerControls here -->
<div id='progress-bar'> ... </div>
<div id='outer-shell'> ... </div>
</div> Assuming I can't change the structure of the markup, and I don't want to wrap view = App.View.PlayerControls.create()
view._insertElementLater(function() { this.$().prependTo('#music-player-container'); }); |
I haven't come up with a use case for #627 yet but this would be one ... |
So I got some code that looks like this:
For some boring background,
App.Controllers.albumList.setup()
loads some JSON via XHR asynchronously, and returns a jQuery Deferred object so that when the data is populated we know when to create the view that consumes that data.Anyway, in this situation the DOM element that gets created has to be prepended, not appended, to another DOM element. There's no method on Ember.View for this.
So after a little scrounging through the Ember.View source I realized I have to copy and paste some internal body logic, because
appendTo
does the wholeget
andset
thing forisVisible
-- and since I'm not sure what that does, I've copied the content body ofEmber.View.appendTo
and am erring on the side of caution here.I'm using
_insertElementLater
becauseApp.Views.ControlPanel.AlbumList
useswillInsertElement
anddidInsertElement
to do some fancy processing and setup before and after the element is inserted.Ideally I'd like not to have to copy the method body of
Ember.View.appendTo
several times, since I don't want to fall out of sync when I update ember.js, so it'd be nice if there was a better way of prepending/appending/whatevering an element into the DOM:Or, am I just going about this the wrong way?
The text was updated successfully, but these errors were encountered: