1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Implicity add Subscription instance to subscriptions collection

This commit is contained in:
Javan Makhmali 2016-03-03 21:40:16 -05:00
parent 6689d7c7b9
commit f1c93ed828
2 changed files with 12 additions and 13 deletions

View file

@ -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?

View file

@ -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)
# Private