small medium large xlarge

18 Jan 2017, 06:32
Mike L (1 post)

I’ve gotten every product on the current page to flash when the price updates.

Here’s the code I currently have that does that:

# ../javascripts/channels/

receive: (data) ->
  $(".store #main").html(data.html)
    $(".entry").css({'background-color' : '#88ff88'}).
      animate({'background-color' : '#fff'}, 1000)

Am I correct in thinking that the channel for the products is the right place to respond to color change? How would I detect changes in the price here?

19 Feb 2017, 15:26
Sam Ruby (634 posts)

It generally would be easiest if you were to detect the change on the server and send the updates to the client using the channel.

What you send across the channel is up to you. If you would like, you could send just the new price and have the code on the client attempt to find, extract, and compare the displayed price with the new value, and respond accordingly. This approach would generally require a bit more pre-planning and work. The code on the client can query the DOM.

In the end, there is no one right way to do what you are asking.

11 Apr 2017, 09:27
Francesco mari (4 posts)

Isn’t a bit overkill to use a websocket for these types of things?

You must be logged in to comment