diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-03 21:12:27 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-03 21:12:27 -0700 |
commit | 2cafbd311fe4ddcaf02cc838088ca24cffe80ceb (patch) | |
tree | 113c57b3fc35cd0c325e291bdcefb782d00bad23 /actioncable/app/assets/javascripts/action_cable/subscription.coffee | |
parent | f8ec3a142fbfc9c6d6ddeb9ae75fd571343dcb40 (diff) | |
parent | 3e4ecbe8e6afda1f96e1e474189a09aa8d19a0a7 (diff) | |
download | rails-2cafbd311fe4ddcaf02cc838088ca24cffe80ceb.tar.gz rails-2cafbd311fe4ddcaf02cc838088ca24cffe80ceb.tar.bz2 rails-2cafbd311fe4ddcaf02cc838088ca24cffe80ceb.zip |
Merge pull request #24039 from javan/actioncable-cleanup
Action Cable: client side 💅
Diffstat (limited to 'actioncable/app/assets/javascripts/action_cable/subscription.coffee')
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable/subscription.coffee | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable/subscription.coffee b/actioncable/app/assets/javascripts/action_cable/subscription.coffee index 339d676933..61a3fb1309 100644 --- a/actioncable/app/assets/javascripts/action_cable/subscription.coffee +++ b/actioncable/app/assets/javascripts/action_cable/subscription.coffee @@ -1,5 +1,5 @@ -# A new subscription is created through the ActionCable.Subscriptions instance available on the consumer. -# It provides a number of callbacks and a method for calling remote procedure calls on the corresponding +# A new subscription is created through the ActionCable.Subscriptions instance available on the consumer. +# It provides a number of callbacks and a method for calling remote procedure calls on the corresponding # Channel instance on the server side. # # An example demonstrates the basic functionality: @@ -7,13 +7,13 @@ # App.appearance = App.cable.subscriptions.create "AppearanceChannel", # connected: -> # # Called once the subscription has been successfully completed -# +# # appear: -> # @perform 'appear', appearing_on: @appearingOn() -# +# # away: -> # @perform 'away' -# +# # appearingOn: -> # $('main').data 'appearing-on' # @@ -27,15 +27,15 @@ # def subscribed # current_user.appear # end -# +# # def unsubscribed # current_user.disappear # end -# +# # def appear(data) # current_user.appear on: data['appearing_on'] # end -# +# # def away # current_user.away # end @@ -44,11 +44,9 @@ # The "AppearanceChannel" name is automatically mapped between the client-side subscription creation and the server-side Ruby class name. # The AppearanceChannel#appear/away public methods are exposed automatically to client-side invocation through the @perform method. class ActionCable.Subscription - constructor: (@subscriptions, params = {}, mixin) -> + constructor: (@consumer, params = {}, mixin) -> @identifier = JSON.stringify(params) extend(this, mixin) - @subscriptions.add(this) - @consumer = @subscriptions.consumer # Perform a channel action with the optional data passed as an attribute perform: (action, data = {}) -> @@ -59,7 +57,7 @@ class ActionCable.Subscription @consumer.send(command: "message", identifier: @identifier, data: JSON.stringify(data)) unsubscribe: -> - @subscriptions.remove(this) + @consumer.subscriptions.remove(this) extend = (object, properties) -> if properties? |