Skip to content

Commit

Permalink
Implicity add Subscription instance to subscriptions collection
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Mar 4, 2016
1 parent 6689d7c commit f1c93ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 10 additions & 12 deletions actioncable/app/assets/javascripts/action_cable/subscription.coffee
@@ -1,19 +1,19 @@
# 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:
#
# 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'
#
Expand All @@ -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
Expand All @@ -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 = {}) ->
Expand All @@ -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?
Expand Down
Expand Up @@ -13,7 +13,8 @@ class ActionCable.Subscriptions
create: (channelName, mixin) ->
channel = channelName
params = if typeof channel is "object" then channel else {channel}
new ActionCable.Subscription this, params, mixin
subscription = new ActionCable.Subscription @consumer, params, mixin
@add(subscription)

This comment has been minimized.

Copy link
@lifo

lifo Mar 4, 2016

Member

@javan I think ActionCable.Subscriptions#create should always return the Subscription object. We expect that in our apps as well.

This comment has been minimized.

Copy link
@javan

javan Mar 4, 2016

Author Contributor

Wups, good catch. Fixed up in #24057.

# Private

Expand Down

0 comments on commit f1c93ed

Please sign in to comment.