action_cable_notifications 0.1.14 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/action_cable_notifications/application.js +1 -0
- data/app/assets/javascripts/action_cable_notifications/cable_notifications.coffee +2 -2
- data/app/assets/javascripts/action_cable_notifications/collection.coffee +90 -21
- data/app/assets/javascripts/action_cable_notifications/default_callbacks.coffee +12 -45
- data/app/assets/javascripts/action_cable_notifications/store.coffee +90 -18
- data/app/assets/javascripts/action_cable_notifications/tracker.js +633 -0
- data/lib/action_cable_notifications/channel.rb +192 -0
- data/lib/action_cable_notifications/channel_actions.rb +144 -0
- data/lib/action_cable_notifications/engine.rb +2 -2
- data/lib/action_cable_notifications/{callbacks.rb → model.rb} +22 -19
- data/lib/action_cable_notifications/version.rb +1 -1
- metadata +34 -4
- data/lib/action_cable_notifications/streams.rb +0 -59
@@ -1,59 +0,0 @@
|
|
1
|
-
module ActionCableNotifications
|
2
|
-
module Streams
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
attr_accessor :stream_notification_options
|
7
|
-
# Actions to be done when the module is included
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_initial_values
|
11
|
-
transmit self.stream_notification_options[:model].notify_initial self.stream_notification_options[:broadcasting]
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def stream_notifications_for(model, options = {}, &block)
|
17
|
-
# Default options
|
18
|
-
options = {
|
19
|
-
model: model,
|
20
|
-
actions: [:create, :update, :destroy],
|
21
|
-
broadcasting: model.model_name.collection,
|
22
|
-
callback: nil,
|
23
|
-
coder: nil,
|
24
|
-
include_initial: false, # Send all records to the subscriber on connection
|
25
|
-
params: params,
|
26
|
-
scope: :all # Default collection scope
|
27
|
-
}.merge(options)
|
28
|
-
|
29
|
-
# Sets channel options
|
30
|
-
self.stream_notification_options = options
|
31
|
-
|
32
|
-
# Checks if model already includes notification callbacks
|
33
|
-
if !model.respond_to? :ActionCableNotificationsOptions
|
34
|
-
model.send('include', ActionCableNotifications::Callbacks)
|
35
|
-
# Set specified options on model
|
36
|
-
end
|
37
|
-
|
38
|
-
# Sets broadcast options if they are not already present in the model
|
39
|
-
if not model.ActionCableNotificationsOptions.key? options[:broadcasting]
|
40
|
-
model.broadcast_notifications_from options[:broadcasting], options
|
41
|
-
end
|
42
|
-
|
43
|
-
# Start streaming
|
44
|
-
stream_from(options[:broadcasting], options[:callback] || block, options.slice(:coder))
|
45
|
-
|
46
|
-
# Transmit initial state if required
|
47
|
-
if options[:include_initial]
|
48
|
-
# XXX: Check if data should be transmitted
|
49
|
-
get_initial_values
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def unsubscribed
|
55
|
-
stop_all_streams
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|