aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/assets/javascripts/cable/consumer.js.coffee7
-rw-r--r--lib/assets/javascripts/cable/subscription.js.coffee7
-rw-r--r--lib/assets/javascripts/cable/subscriptions.js.coffee5
3 files changed, 10 insertions, 9 deletions
diff --git a/lib/assets/javascripts/cable/consumer.js.coffee b/lib/assets/javascripts/cable/consumer.js.coffee
index b01ae586aa..1df6536831 100644
--- a/lib/assets/javascripts/cable/consumer.js.coffee
+++ b/lib/assets/javascripts/cable/consumer.js.coffee
@@ -12,7 +12,7 @@
#
# @App = {}
# App.cable = Cable.createConsumer "http://example.com/accounts/1"
-# App.appearance = App.cable.createSubscription "AppearanceChannel"
+# App.appearance = App.cable.subscriptions.create "AppearanceChannel"
#
# For more details on how you'd configure an actual channel subscription, see Cable.Subscription.
class Cable.Consumer
@@ -21,11 +21,6 @@ class Cable.Consumer
@connection = new Cable.Connection this
@connectionMonitor = new Cable.ConnectionMonitor this
- createSubscription: (channelName, mixin) ->
- channel = channelName
- params = if typeof channel is "object" then channel else {channel}
- new Cable.Subscription this, params, mixin
-
send: (data) ->
@connection.send(data)
diff --git a/lib/assets/javascripts/cable/subscription.js.coffee b/lib/assets/javascripts/cable/subscription.js.coffee
index 17f5a10868..b60033098a 100644
--- a/lib/assets/javascripts/cable/subscription.js.coffee
+++ b/lib/assets/javascripts/cable/subscription.js.coffee
@@ -1,8 +1,9 @@
class Cable.Subscription
- constructor: (@consumer, params = {}, mixin) ->
+ constructor: (@subscriptions, params = {}, mixin) ->
@identifier = JSON.stringify(params)
extend(this, mixin)
- @consumer.subscriptions.add(this)
+ @subscriptions.add(this)
+ @consumer = @subscriptions.consumer
# Perform a channel action with the optional data passed as an attribute
perform: (action, data = {}) ->
@@ -13,7 +14,7 @@ class Cable.Subscription
@consumer.send(command: "message", identifier: @identifier, data: JSON.stringify(data))
unsubscribe: ->
- @consumer.subscriptions.remove(this)
+ @subscriptions.remove(this)
extend = (object, properties) ->
if properties?
diff --git a/lib/assets/javascripts/cable/subscriptions.js.coffee b/lib/assets/javascripts/cable/subscriptions.js.coffee
index 7cb008ca67..884257a12d 100644
--- a/lib/assets/javascripts/cable/subscriptions.js.coffee
+++ b/lib/assets/javascripts/cable/subscriptions.js.coffee
@@ -2,6 +2,11 @@ class Cable.Subscriptions
constructor: (@consumer) ->
@subscriptions = []
+ create: (channelName, mixin) ->
+ channel = channelName
+ params = if typeof channel is "object" then channel else {channel}
+ new Cable.Subscription this, params, mixin
+
add: (subscription) ->
@subscriptions.push(subscription)
@notify(subscription, "initialized")