cable_ready 4.1.1 → 4.3.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +77 -74
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/lib/cable_ready.rb +2 -0
- data/lib/cable_ready/broadcaster.rb +7 -1
- data/lib/cable_ready/channel.rb +20 -202
- data/lib/cable_ready/channels.rb +56 -7
- data/lib/cable_ready/version.rb +3 -1
- metadata +9 -10
- data/yarn.lock +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 346546ced0777dc18c18bc02e3271e3c6d159b10099ed914d529fe7d7cb1b004
|
4
|
+
data.tar.gz: 6017a0897cbede70a047d48411a7d7120e733429dc9a0695262e91ae7e8bd868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88da1b32f36bd19e6f52421d1c779b9371f5b6149af266cda49bb5315ea67e7b88c34a3e2387af78854fe3391b1cd9d25ef32ce69443121d7419c1366502baee
|
7
|
+
data.tar.gz: 45ac230c4439062a6e79b5ae5846da725dc261cd6f6c88758b83ab1614c8165d6c3090997ee3c84058ed6629296107152f303ba0c4107371927ca073b5ef01d6
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,79 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cable_ready (4.
|
4
|
+
cable_ready (4.3.0.pre2)
|
5
5
|
rails (>= 5.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (6.0.
|
11
|
-
actionpack (= 6.0.
|
10
|
+
actioncable (6.0.3.2)
|
11
|
+
actionpack (= 6.0.3.2)
|
12
12
|
nio4r (~> 2.0)
|
13
13
|
websocket-driver (>= 0.6.1)
|
14
|
-
actionmailbox (6.0.
|
15
|
-
actionpack (= 6.0.
|
16
|
-
activejob (= 6.0.
|
17
|
-
activerecord (= 6.0.
|
18
|
-
activestorage (= 6.0.
|
19
|
-
activesupport (= 6.0.
|
14
|
+
actionmailbox (6.0.3.2)
|
15
|
+
actionpack (= 6.0.3.2)
|
16
|
+
activejob (= 6.0.3.2)
|
17
|
+
activerecord (= 6.0.3.2)
|
18
|
+
activestorage (= 6.0.3.2)
|
19
|
+
activesupport (= 6.0.3.2)
|
20
20
|
mail (>= 2.7.1)
|
21
|
-
actionmailer (6.0.
|
22
|
-
actionpack (= 6.0.
|
23
|
-
actionview (= 6.0.
|
24
|
-
activejob (= 6.0.
|
21
|
+
actionmailer (6.0.3.2)
|
22
|
+
actionpack (= 6.0.3.2)
|
23
|
+
actionview (= 6.0.3.2)
|
24
|
+
activejob (= 6.0.3.2)
|
25
25
|
mail (~> 2.5, >= 2.5.4)
|
26
26
|
rails-dom-testing (~> 2.0)
|
27
|
-
actionpack (6.0.
|
28
|
-
actionview (= 6.0.
|
29
|
-
activesupport (= 6.0.
|
27
|
+
actionpack (6.0.3.2)
|
28
|
+
actionview (= 6.0.3.2)
|
29
|
+
activesupport (= 6.0.3.2)
|
30
30
|
rack (~> 2.0, >= 2.0.8)
|
31
31
|
rack-test (>= 0.6.3)
|
32
32
|
rails-dom-testing (~> 2.0)
|
33
33
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
34
|
-
actiontext (6.0.
|
35
|
-
actionpack (= 6.0.
|
36
|
-
activerecord (= 6.0.
|
37
|
-
activestorage (= 6.0.
|
38
|
-
activesupport (= 6.0.
|
34
|
+
actiontext (6.0.3.2)
|
35
|
+
actionpack (= 6.0.3.2)
|
36
|
+
activerecord (= 6.0.3.2)
|
37
|
+
activestorage (= 6.0.3.2)
|
38
|
+
activesupport (= 6.0.3.2)
|
39
39
|
nokogiri (>= 1.8.5)
|
40
|
-
actionview (6.0.
|
41
|
-
activesupport (= 6.0.
|
40
|
+
actionview (6.0.3.2)
|
41
|
+
activesupport (= 6.0.3.2)
|
42
42
|
builder (~> 3.1)
|
43
43
|
erubi (~> 1.4)
|
44
44
|
rails-dom-testing (~> 2.0)
|
45
45
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
46
|
-
activejob (6.0.
|
47
|
-
activesupport (= 6.0.
|
46
|
+
activejob (6.0.3.2)
|
47
|
+
activesupport (= 6.0.3.2)
|
48
48
|
globalid (>= 0.3.6)
|
49
|
-
activemodel (6.0.
|
50
|
-
activesupport (= 6.0.
|
51
|
-
activerecord (6.0.
|
52
|
-
activemodel (= 6.0.
|
53
|
-
activesupport (= 6.0.
|
54
|
-
activestorage (6.0.
|
55
|
-
actionpack (= 6.0.
|
56
|
-
activejob (= 6.0.
|
57
|
-
activerecord (= 6.0.
|
49
|
+
activemodel (6.0.3.2)
|
50
|
+
activesupport (= 6.0.3.2)
|
51
|
+
activerecord (6.0.3.2)
|
52
|
+
activemodel (= 6.0.3.2)
|
53
|
+
activesupport (= 6.0.3.2)
|
54
|
+
activestorage (6.0.3.2)
|
55
|
+
actionpack (= 6.0.3.2)
|
56
|
+
activejob (= 6.0.3.2)
|
57
|
+
activerecord (= 6.0.3.2)
|
58
58
|
marcel (~> 0.3.1)
|
59
|
-
activesupport (6.0.
|
59
|
+
activesupport (6.0.3.2)
|
60
60
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
61
61
|
i18n (>= 0.7, < 2)
|
62
62
|
minitest (~> 5.1)
|
63
63
|
tzinfo (~> 1.1)
|
64
|
-
zeitwerk (~> 2.2)
|
65
|
-
ast (2.4.
|
64
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
65
|
+
ast (2.4.1)
|
66
66
|
builder (3.2.4)
|
67
|
-
coderay (1.1.
|
67
|
+
coderay (1.1.3)
|
68
68
|
concurrent-ruby (1.1.6)
|
69
69
|
crass (1.0.6)
|
70
70
|
erubi (1.9.0)
|
71
71
|
globalid (0.4.2)
|
72
72
|
activesupport (>= 4.2.0)
|
73
|
-
i18n (1.8.
|
73
|
+
i18n (1.8.3)
|
74
74
|
concurrent-ruby (~> 1.0)
|
75
|
-
|
76
|
-
loofah (2.5.0)
|
75
|
+
loofah (2.6.0)
|
77
76
|
crass (~> 1.0.2)
|
78
77
|
nokogiri (>= 1.5.9)
|
79
78
|
mail (2.7.1)
|
@@ -81,84 +80,88 @@ GEM
|
|
81
80
|
marcel (0.3.3)
|
82
81
|
mimemagic (~> 0.3.2)
|
83
82
|
method_source (0.9.2)
|
84
|
-
mimemagic (0.3.
|
83
|
+
mimemagic (0.3.5)
|
85
84
|
mini_mime (1.0.2)
|
86
85
|
mini_portile2 (2.4.0)
|
87
|
-
minitest (5.14.
|
86
|
+
minitest (5.14.1)
|
88
87
|
nio4r (2.5.2)
|
89
88
|
nokogiri (1.10.9)
|
90
89
|
mini_portile2 (~> 2.4.0)
|
91
|
-
parallel (1.19.
|
92
|
-
parser (2.7.1.
|
93
|
-
ast (~> 2.4.
|
90
|
+
parallel (1.19.2)
|
91
|
+
parser (2.7.1.4)
|
92
|
+
ast (~> 2.4.1)
|
94
93
|
pry (0.12.2)
|
95
94
|
coderay (~> 1.1.0)
|
96
95
|
method_source (~> 0.9.0)
|
97
96
|
pry-nav (0.3.0)
|
98
97
|
pry (>= 0.9.10, < 0.13.0)
|
99
|
-
rack (2.2.
|
98
|
+
rack (2.2.3)
|
100
99
|
rack-test (1.1.0)
|
101
100
|
rack (>= 1.0, < 3)
|
102
|
-
rails (6.0.
|
103
|
-
actioncable (= 6.0.
|
104
|
-
actionmailbox (= 6.0.
|
105
|
-
actionmailer (= 6.0.
|
106
|
-
actionpack (= 6.0.
|
107
|
-
actiontext (= 6.0.
|
108
|
-
actionview (= 6.0.
|
109
|
-
activejob (= 6.0.
|
110
|
-
activemodel (= 6.0.
|
111
|
-
activerecord (= 6.0.
|
112
|
-
activestorage (= 6.0.
|
113
|
-
activesupport (= 6.0.
|
101
|
+
rails (6.0.3.2)
|
102
|
+
actioncable (= 6.0.3.2)
|
103
|
+
actionmailbox (= 6.0.3.2)
|
104
|
+
actionmailer (= 6.0.3.2)
|
105
|
+
actionpack (= 6.0.3.2)
|
106
|
+
actiontext (= 6.0.3.2)
|
107
|
+
actionview (= 6.0.3.2)
|
108
|
+
activejob (= 6.0.3.2)
|
109
|
+
activemodel (= 6.0.3.2)
|
110
|
+
activerecord (= 6.0.3.2)
|
111
|
+
activestorage (= 6.0.3.2)
|
112
|
+
activesupport (= 6.0.3.2)
|
114
113
|
bundler (>= 1.3.0)
|
115
|
-
railties (= 6.0.
|
114
|
+
railties (= 6.0.3.2)
|
116
115
|
sprockets-rails (>= 2.0.0)
|
117
116
|
rails-dom-testing (2.0.3)
|
118
117
|
activesupport (>= 4.2.0)
|
119
118
|
nokogiri (>= 1.6)
|
120
119
|
rails-html-sanitizer (1.3.0)
|
121
120
|
loofah (~> 2.3)
|
122
|
-
railties (6.0.
|
123
|
-
actionpack (= 6.0.
|
124
|
-
activesupport (= 6.0.
|
121
|
+
railties (6.0.3.2)
|
122
|
+
actionpack (= 6.0.3.2)
|
123
|
+
activesupport (= 6.0.3.2)
|
125
124
|
method_source
|
126
125
|
rake (>= 0.8.7)
|
127
126
|
thor (>= 0.20.3, < 2.0)
|
128
127
|
rainbow (3.0.0)
|
129
128
|
rake (13.0.1)
|
129
|
+
regexp_parser (1.7.1)
|
130
130
|
rexml (3.2.4)
|
131
|
-
rubocop (0.
|
132
|
-
jaro_winkler (~> 1.5.1)
|
131
|
+
rubocop (0.85.1)
|
133
132
|
parallel (~> 1.10)
|
134
133
|
parser (>= 2.7.0.1)
|
135
134
|
rainbow (>= 2.2.2, < 4.0)
|
135
|
+
regexp_parser (>= 1.7)
|
136
136
|
rexml
|
137
|
+
rubocop-ast (>= 0.0.3)
|
137
138
|
ruby-progressbar (~> 1.7)
|
138
|
-
unicode-display_width (>= 1.4.0, <
|
139
|
-
rubocop-
|
139
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
140
|
+
rubocop-ast (0.1.0)
|
141
|
+
parser (>= 2.7.0.1)
|
142
|
+
rubocop-performance (1.6.1)
|
140
143
|
rubocop (>= 0.71.0)
|
141
144
|
ruby-progressbar (1.10.1)
|
142
|
-
sprockets (4.0.
|
145
|
+
sprockets (4.0.2)
|
143
146
|
concurrent-ruby (~> 1.0)
|
144
147
|
rack (> 1, < 3)
|
145
148
|
sprockets-rails (3.2.1)
|
146
149
|
actionpack (>= 4.0)
|
147
150
|
activesupport (>= 4.0)
|
148
151
|
sprockets (>= 3.0.0)
|
149
|
-
standard (0.
|
150
|
-
rubocop (~> 0.
|
151
|
-
rubocop-performance (~> 1.
|
152
|
+
standard (0.4.7)
|
153
|
+
rubocop (~> 0.85.0)
|
154
|
+
rubocop-performance (~> 1.6.0)
|
152
155
|
standardrb (1.0.0)
|
153
156
|
standard
|
154
157
|
thor (1.0.1)
|
155
158
|
thread_safe (0.3.6)
|
156
159
|
tzinfo (1.2.7)
|
157
160
|
thread_safe (~> 0.1)
|
158
|
-
unicode-display_width (1.
|
159
|
-
websocket-driver (0.7.
|
161
|
+
unicode-display_width (1.7.0)
|
162
|
+
websocket-driver (0.7.2)
|
160
163
|
websocket-extensions (>= 0.1.0)
|
161
|
-
websocket-extensions (0.1.
|
164
|
+
websocket-extensions (0.1.5)
|
162
165
|
zeitwerk (2.3.0)
|
163
166
|
|
164
167
|
PLATFORMS
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
|
12
12
|
</a>
|
13
13
|
<a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
|
14
|
-
<img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-
|
14
|
+
<img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-375-brightgreen.svg?style=flat" />
|
15
15
|
</a>
|
16
16
|
<a href="https://cableready.stimulusreflex.com" target="_blank">
|
17
17
|
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
data/Rakefile
CHANGED
data/lib/cable_ready.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "channels"
|
2
4
|
|
3
5
|
module CableReady
|
@@ -5,7 +7,11 @@ module CableReady
|
|
5
7
|
extend ::ActiveSupport::Concern
|
6
8
|
|
7
9
|
def cable_ready
|
8
|
-
|
10
|
+
CableReady::Channels.instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def dom_id(record, prefix = nil)
|
14
|
+
"##{ActionView::RecordIdentifier.dom_id(record, prefix)}"
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
data/lib/cable_ready/channel.rb
CHANGED
@@ -1,222 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CableReady
|
2
4
|
class Channel
|
3
|
-
attr_reader :
|
4
|
-
|
5
|
-
# Example Operations Payload:
|
6
|
-
#
|
7
|
-
# {
|
8
|
-
# # Cookies .....................................................................................................
|
9
|
-
#
|
10
|
-
# set_cookie: [
|
11
|
-
# {cookie: "example=value; path=/; expires=Sat, 07 Mar 2020 16:19:19 GMT"},
|
12
|
-
# ...
|
13
|
-
# ]
|
14
|
-
#
|
15
|
-
# # DOM Events ..................................................................................................
|
16
|
-
#
|
17
|
-
# dispatch_event: [{
|
18
|
-
# name: "string",
|
19
|
-
# detail: "object",
|
20
|
-
# selector: "string",
|
21
|
-
# }, ...],
|
22
|
-
#
|
23
|
-
# # Element Mutations ...........................................................................................
|
24
|
-
#
|
25
|
-
# morph: [{
|
26
|
-
# selector: "string",
|
27
|
-
# html: "string"
|
28
|
-
# children_only: true|false,
|
29
|
-
# permanent_attribute_name: "string",
|
30
|
-
# focus_selector: "string",
|
31
|
-
# }, ...],
|
32
|
-
#
|
33
|
-
# inner_html: [{
|
34
|
-
# selector: "string",
|
35
|
-
# focus_selector: "string",
|
36
|
-
# html: "string"
|
37
|
-
# }, ...],
|
38
|
-
#
|
39
|
-
# outer_html: [{
|
40
|
-
# selector: "string",
|
41
|
-
# focus_selector: "string",
|
42
|
-
# html: "string"
|
43
|
-
# }, ...],
|
44
|
-
#
|
45
|
-
# text_content: [{
|
46
|
-
# selector: "string",
|
47
|
-
# text: "string"
|
48
|
-
# }, ...]
|
49
|
-
#
|
50
|
-
# insert_adjacent_html: [{
|
51
|
-
# selector: "string",
|
52
|
-
# focus_selector: "string",
|
53
|
-
# position: "string",
|
54
|
-
# html: "string"
|
55
|
-
# }, ...],
|
56
|
-
#
|
57
|
-
# insert_adjacent_text: [{
|
58
|
-
# selector: "string",
|
59
|
-
# position: "string",
|
60
|
-
# text: "string"
|
61
|
-
# }, ...],
|
62
|
-
#
|
63
|
-
# remove: [{
|
64
|
-
# selector: "string",
|
65
|
-
# focus_selector: "string,
|
66
|
-
# }, ...],
|
67
|
-
#
|
68
|
-
# set_value: [{
|
69
|
-
# selector: "string",
|
70
|
-
# value: "string"
|
71
|
-
# }, ...],
|
72
|
-
#
|
73
|
-
# # Attribute Mutations .........................................................................................
|
74
|
-
#
|
75
|
-
# set_attribute: [{
|
76
|
-
# selector: "string",
|
77
|
-
# name: "string",
|
78
|
-
# value: "string"
|
79
|
-
# }, ...],
|
80
|
-
#
|
81
|
-
# remove_attribute: [{
|
82
|
-
# selector: "string",
|
83
|
-
# name: "string"
|
84
|
-
# }, ...],
|
85
|
-
#
|
86
|
-
# # CSS Class Mutations .........................................................................................
|
87
|
-
#
|
88
|
-
# add_css_class: [{
|
89
|
-
# selector: "string",
|
90
|
-
# name: "string"
|
91
|
-
# }, ...],
|
92
|
-
#
|
93
|
-
# remove_css_class: [{
|
94
|
-
# selector: "string",
|
95
|
-
# name: "string"
|
96
|
-
# }, ...],
|
97
|
-
#
|
98
|
-
# # Style Mutations ...........................................................................................
|
99
|
-
#
|
100
|
-
# set_style: [{
|
101
|
-
# selector: "string",
|
102
|
-
# name: "string",
|
103
|
-
# value: "string"
|
104
|
-
# }, ...],
|
105
|
-
#
|
106
|
-
# # Dataset Mutations ...........................................................................................
|
107
|
-
#
|
108
|
-
# set_dataset_property: [{
|
109
|
-
# selector: "string",
|
110
|
-
# name: "string",
|
111
|
-
# value: "string"
|
112
|
-
# }, ...],
|
113
|
-
# }
|
114
|
-
def initialize(name)
|
115
|
-
@name = name
|
116
|
-
@operations = stub
|
117
|
-
end
|
5
|
+
attr_reader :identifier, :operations, :available_operations
|
118
6
|
|
119
|
-
def
|
120
|
-
@
|
7
|
+
def initialize(identifier, available_operations)
|
8
|
+
@identifier = identifier
|
9
|
+
@available_operations = available_operations
|
10
|
+
reset
|
11
|
+
available_operations.each do |available_operation, implementation|
|
12
|
+
define_singleton_method available_operation, &implementation
|
13
|
+
end
|
121
14
|
end
|
122
15
|
|
123
|
-
def broadcast
|
16
|
+
def broadcast(clear)
|
124
17
|
operations.select! { |_, list| list.present? }
|
125
18
|
operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
|
126
|
-
ActionCable.server.broadcast
|
127
|
-
clear
|
128
|
-
end
|
129
|
-
|
130
|
-
def set_cookie(value)
|
131
|
-
add_operation(:set_cookie, {cookie: value})
|
132
|
-
end
|
133
|
-
|
134
|
-
def dispatch_event(options = {})
|
135
|
-
add_operation(:dispatch_event, options)
|
136
|
-
end
|
137
|
-
|
138
|
-
def morph(options = {})
|
139
|
-
add_operation(:morph, options)
|
19
|
+
ActionCable.server.broadcast identifier, "cableReady" => true, "operations" => operations
|
20
|
+
reset if clear
|
140
21
|
end
|
141
22
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
add_operation(:outer_html, options)
|
148
|
-
end
|
149
|
-
|
150
|
-
def text_content(options = {})
|
151
|
-
add_operation(:text_content, options)
|
152
|
-
end
|
153
|
-
|
154
|
-
def insert_adjacent_html(options = {})
|
155
|
-
add_operation(:insert_adjacent_html, options)
|
156
|
-
end
|
157
|
-
|
158
|
-
def insert_adjacent_text(options = {})
|
159
|
-
add_operation(:insert_adjacent_text, options)
|
160
|
-
end
|
161
|
-
|
162
|
-
def remove(options = {})
|
163
|
-
add_operation(:remove, options)
|
164
|
-
end
|
165
|
-
|
166
|
-
def set_value(options = {})
|
167
|
-
add_operation(:set_value, options)
|
168
|
-
end
|
169
|
-
|
170
|
-
def set_attribute(options = {})
|
171
|
-
add_operation(:set_attribute, options)
|
172
|
-
end
|
173
|
-
|
174
|
-
def remove_attribute(options = {})
|
175
|
-
add_operation(:remove_attribute, options)
|
176
|
-
end
|
177
|
-
|
178
|
-
def add_css_class(options = {})
|
179
|
-
add_operation(:add_css_class, options)
|
180
|
-
end
|
181
|
-
|
182
|
-
def remove_css_class(options = {})
|
183
|
-
add_operation(:remove_css_class, options)
|
184
|
-
end
|
185
|
-
|
186
|
-
def set_style(options = {})
|
187
|
-
add_operation(:set_style, options)
|
188
|
-
end
|
189
|
-
|
190
|
-
def set_dataset_property(options = {})
|
191
|
-
add_operation(:set_dataset_property, options)
|
23
|
+
def broadcast_to(model, clear)
|
24
|
+
operations.select! { |_, list| list.present? }
|
25
|
+
operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
|
26
|
+
identifier.broadcast_to model, "cableReady" => true, "operations" => operations
|
27
|
+
reset if clear
|
192
28
|
end
|
193
29
|
|
194
30
|
private
|
195
31
|
|
196
32
|
def add_operation(key, options)
|
197
|
-
operations[key] ||= []
|
198
33
|
operations[key] << options
|
199
34
|
end
|
200
35
|
|
201
|
-
def
|
202
|
-
{
|
203
|
-
add_css_class: [],
|
204
|
-
dispatch_event: [],
|
205
|
-
inner_html: [],
|
206
|
-
insert_adjacent_html: [],
|
207
|
-
insert_adjacent_text: [],
|
208
|
-
morph: [],
|
209
|
-
outer_html: [],
|
210
|
-
remove: [],
|
211
|
-
remove_attribute: [],
|
212
|
-
remove_css_class: [],
|
213
|
-
set_attribute: [],
|
214
|
-
set_cookie: [],
|
215
|
-
set_dataset_property: [],
|
216
|
-
set_style: [],
|
217
|
-
set_value: [],
|
218
|
-
text_content: []
|
219
|
-
}
|
36
|
+
def reset
|
37
|
+
@operations = Hash.new { |hash, operation| hash[operation] = [] }
|
220
38
|
end
|
221
39
|
end
|
222
40
|
end
|
data/lib/cable_ready/channels.rb
CHANGED
@@ -1,22 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "channel"
|
2
4
|
|
3
5
|
module CableReady
|
4
6
|
class Channels
|
7
|
+
include Singleton
|
8
|
+
attr_accessor :operations
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield CableReady::Channels.instance if block_given?
|
12
|
+
end
|
13
|
+
|
5
14
|
def initialize
|
6
15
|
@channels = {}
|
16
|
+
@operations = {}
|
17
|
+
%i[
|
18
|
+
add_css_class
|
19
|
+
console_log
|
20
|
+
dispatch_event
|
21
|
+
inner_html
|
22
|
+
insert_adjacent_html
|
23
|
+
insert_adjacent_text
|
24
|
+
morph
|
25
|
+
notification
|
26
|
+
outer_html
|
27
|
+
remove
|
28
|
+
remove_attribute
|
29
|
+
remove_css_class
|
30
|
+
set_attribute
|
31
|
+
set_cookie
|
32
|
+
set_dataset_property
|
33
|
+
set_property
|
34
|
+
set_style
|
35
|
+
set_styles
|
36
|
+
set_value
|
37
|
+
text_content
|
38
|
+
].each do |operation|
|
39
|
+
add_operation operation
|
40
|
+
end
|
7
41
|
end
|
8
42
|
|
9
|
-
def
|
10
|
-
@
|
43
|
+
def add_operation(operation, &implementation)
|
44
|
+
@operations[operation] = implementation || ->(options = {}) { add_operation(operation, options) }
|
11
45
|
end
|
12
46
|
|
13
|
-
def
|
14
|
-
@channels
|
47
|
+
def [](identifier)
|
48
|
+
@channels[identifier] ||= CableReady::Channel.new(identifier, operations)
|
49
|
+
end
|
50
|
+
|
51
|
+
def broadcast(*identifiers, clear: true)
|
52
|
+
@channels.values
|
53
|
+
.reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
|
54
|
+
.select { |channel| channel.identifier.is_a?(String) }
|
55
|
+
.tap do |channels|
|
56
|
+
channels.each { |channel| @channels[channel.identifier].broadcast(clear) }
|
57
|
+
channels.each { |channel| @channels.except!(channel.identifier) if clear }
|
58
|
+
end
|
15
59
|
end
|
16
60
|
|
17
|
-
def
|
18
|
-
@channels.values
|
19
|
-
|
61
|
+
def broadcast_to(model, *identifiers, clear: true)
|
62
|
+
@channels.values
|
63
|
+
.reject { |channel| identifiers.any? && identifiers.exclude?(channel.identifier) }
|
64
|
+
.reject { |channel| channel.identifier.is_a?(String) }
|
65
|
+
.tap do |channels|
|
66
|
+
channels.each { |channel| @channels[channel.identifier].broadcast_to(model, clear) }
|
67
|
+
channels.each { |channel| @channels.except!(channel.identifier) if clear }
|
68
|
+
end
|
20
69
|
end
|
21
70
|
end
|
22
71
|
end
|
data/lib/cable_ready/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cable_ready
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- natehop@gmail.com
|
86
86
|
executables: []
|
@@ -104,12 +104,11 @@ files:
|
|
104
104
|
- lib/cable_ready/channels.rb
|
105
105
|
- lib/cable_ready/version.rb
|
106
106
|
- tags
|
107
|
-
- yarn.lock
|
108
107
|
homepage: https://github.com/hopsoft/cable_ready
|
109
108
|
licenses:
|
110
109
|
- MIT
|
111
110
|
metadata: {}
|
112
|
-
post_install_message:
|
111
|
+
post_install_message:
|
113
112
|
rdoc_options: []
|
114
113
|
require_paths:
|
115
114
|
- lib
|
@@ -120,12 +119,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
119
|
version: '0'
|
121
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
121
|
requirements:
|
123
|
-
- - "
|
122
|
+
- - ">"
|
124
123
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
124
|
+
version: 1.3.1
|
126
125
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
128
|
-
signing_key:
|
126
|
+
rubygems_version: 3.0.3
|
127
|
+
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: Out-of-Band Server Triggered DOM Operations
|
131
130
|
test_files: []
|
data/yarn.lock
DELETED