I have the following ember controller that is going to wait for json objects to be passed from a websocket server via the onmessage handler:
Lead.Controllers.ParsingController = Ember.Object.extend
start_parsing: (url_search) ->
socket = new Lead.WebSocket("ws://#{document.domain}:61615")
socket.onopen = (evt) ->
socket.send url_search.search_url
socket.onmessage = (evt) ->
Lead.leads_controller.addLead evt.data
My LeadsController currently looks like this:
Lead.Controllers.Leads = Ember.Object.extend
addLead: (lead) ->
@view = Ember.View.create
controller: @
#etc.
My questions are these:
- Am I right not to use an ArrayController because they are only to be used for collections? Sorry for the obvious question but I just want to check.
- If I create a new view, everytime the addLead method is called, will I need to keep a reference to each view in an internal array and iterate over the array calling dispose on each child view when I am disposing of the main view?
- Would I be better off creating a separate controller for each child view that is appended? I am guessing no but would like to check.
Any help or guidance on these questions would be greatly appreciated.
I’m not going to answer your specific questions, but rather suggest an alternate implementation that I think would be more idiomatic Ember and be simpler.
It’s hard to tell what your broader view layer looks like, but I based on my guess at your problem domain, I would think that you would have a
#eachhelper orCollectionViewthat is databound to aleadsControllerwhich subclassesArrayProxy. When the json comes in from the websocket, callpushObjecton theleadsController. Bindings will automatically update and render the new lead in the view output.If I misunderstood the app’s functionality, please do clarify.