Reputation: 28898
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:
Any help or guidance on these questions would be greatly appreciated.
Upvotes: 1
Views: 438
Reputation: 8389
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 #each
helper or CollectionView
that is databound to a leadsController
which subclasses ArrayProxy
. When the json comes in from the websocket, call pushObject
on the leadsController
. Bindings will automatically update and render the new lead in the view output.
If I misunderstood the app's functionality, please do clarify.
Upvotes: 4