stimulus_reflex 3.4.2 → 3.5.0.pre0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +587 -495
- data/Gemfile.lock +120 -172
- data/LATEST +1 -0
- data/README.md +10 -10
- data/app/channels/stimulus_reflex/channel.rb +40 -62
- data/lib/generators/USAGE +1 -1
- data/lib/generators/stimulus_reflex/{config_generator.rb → initializer_generator.rb} +3 -3
- data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +3 -2
- data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +6 -1
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +7 -4
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +2 -2
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +12 -5
- data/lib/stimulus_reflex/cable_ready_channels.rb +6 -2
- data/lib/stimulus_reflex/callbacks.rb +55 -5
- data/lib/stimulus_reflex/concern_enhancer.rb +37 -0
- data/lib/stimulus_reflex/configuration.rb +2 -1
- data/lib/stimulus_reflex/element.rb +31 -7
- data/lib/stimulus_reflex/policies/reflex_invocation_policy.rb +28 -0
- data/lib/stimulus_reflex/reflex.rb +35 -20
- data/lib/stimulus_reflex/reflex_data.rb +79 -0
- data/lib/stimulus_reflex/reflex_factory.rb +23 -54
- data/lib/stimulus_reflex/request_parameters.rb +19 -0
- data/lib/stimulus_reflex/{logger.rb → utils/logger.rb} +0 -2
- data/lib/stimulus_reflex/{sanity_checker.rb → utils/sanity_checker.rb} +58 -10
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/stimulus_reflex.rb +8 -2
- data/lib/tasks/stimulus_reflex/install.rake +6 -4
- data/package.json +6 -5
- data/stimulus_reflex.gemspec +5 -5
- data/test/broadcasters/broadcaster_test_case.rb +1 -1
- data/test/broadcasters/nothing_broadcaster_test.rb +5 -3
- data/test/broadcasters/page_broadcaster_test.rb +8 -4
- data/test/broadcasters/selector_broadcaster_test.rb +171 -55
- data/test/callbacks_test.rb +652 -0
- data/test/concern_enhancer_test.rb +54 -0
- data/test/element_test.rb +181 -0
- data/test/reflex_test.rb +1 -1
- data/test/test_helper.rb +4 -34
- data/test/tmp/app/reflexes/application_reflex.rb +12 -0
- data/test/tmp/app/reflexes/user_reflex.rb +44 -0
- data/yarn.lock +1138 -919
- metadata +36 -23
- data/test/reflex_factory_test.rb +0 -79
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (3.
|
5
|
-
cable_ready (
|
4
|
+
stimulus_reflex (3.5.0.pre0)
|
5
|
+
cable_ready (= 5.0.0.pre0)
|
6
6
|
nokogiri
|
7
7
|
rack
|
8
8
|
rails (>= 5.2)
|
@@ -11,221 +11,169 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
actioncable (
|
15
|
-
actionpack (=
|
16
|
-
activesupport (=
|
14
|
+
actioncable (6.1.3.2)
|
15
|
+
actionpack (= 6.1.3.2)
|
16
|
+
activesupport (= 6.1.3.2)
|
17
17
|
nio4r (~> 2.0)
|
18
18
|
websocket-driver (>= 0.6.1)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
activesupport (= 7.1.3.2)
|
19
|
+
actionmailbox (6.1.3.2)
|
20
|
+
actionpack (= 6.1.3.2)
|
21
|
+
activejob (= 6.1.3.2)
|
22
|
+
activerecord (= 6.1.3.2)
|
23
|
+
activestorage (= 6.1.3.2)
|
24
|
+
activesupport (= 6.1.3.2)
|
26
25
|
mail (>= 2.7.1)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
actionview (= 7.1.3.2)
|
33
|
-
activejob (= 7.1.3.2)
|
34
|
-
activesupport (= 7.1.3.2)
|
26
|
+
actionmailer (6.1.3.2)
|
27
|
+
actionpack (= 6.1.3.2)
|
28
|
+
actionview (= 6.1.3.2)
|
29
|
+
activejob (= 6.1.3.2)
|
30
|
+
activesupport (= 6.1.3.2)
|
35
31
|
mail (~> 2.5, >= 2.5.4)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
actionview (= 7.1.3.2)
|
42
|
-
activesupport (= 7.1.3.2)
|
43
|
-
nokogiri (>= 1.8.5)
|
44
|
-
racc
|
45
|
-
rack (>= 2.2.4)
|
46
|
-
rack-session (>= 1.0.1)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
actionpack (6.1.3.2)
|
34
|
+
actionview (= 6.1.3.2)
|
35
|
+
activesupport (= 6.1.3.2)
|
36
|
+
rack (~> 2.0, >= 2.0.9)
|
47
37
|
rack-test (>= 0.6.3)
|
48
|
-
rails-dom-testing (~> 2.
|
49
|
-
rails-html-sanitizer (~> 1.
|
50
|
-
actiontext (
|
51
|
-
actionpack (=
|
52
|
-
activerecord (=
|
53
|
-
activestorage (=
|
54
|
-
activesupport (=
|
55
|
-
globalid (>= 0.6.0)
|
38
|
+
rails-dom-testing (~> 2.0)
|
39
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
40
|
+
actiontext (6.1.3.2)
|
41
|
+
actionpack (= 6.1.3.2)
|
42
|
+
activerecord (= 6.1.3.2)
|
43
|
+
activestorage (= 6.1.3.2)
|
44
|
+
activesupport (= 6.1.3.2)
|
56
45
|
nokogiri (>= 1.8.5)
|
57
|
-
actionview (
|
58
|
-
activesupport (=
|
46
|
+
actionview (6.1.3.2)
|
47
|
+
activesupport (= 6.1.3.2)
|
59
48
|
builder (~> 3.1)
|
60
|
-
erubi (~> 1.
|
61
|
-
rails-dom-testing (~> 2.
|
62
|
-
rails-html-sanitizer (~> 1.
|
63
|
-
activejob (
|
64
|
-
activesupport (=
|
49
|
+
erubi (~> 1.4)
|
50
|
+
rails-dom-testing (~> 2.0)
|
51
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
52
|
+
activejob (6.1.3.2)
|
53
|
+
activesupport (= 6.1.3.2)
|
65
54
|
globalid (>= 0.3.6)
|
66
|
-
activemodel (
|
67
|
-
activesupport (=
|
68
|
-
activerecord (
|
69
|
-
activemodel (=
|
70
|
-
activesupport (=
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
activesupport (
|
79
|
-
base64
|
80
|
-
bigdecimal
|
55
|
+
activemodel (6.1.3.2)
|
56
|
+
activesupport (= 6.1.3.2)
|
57
|
+
activerecord (6.1.3.2)
|
58
|
+
activemodel (= 6.1.3.2)
|
59
|
+
activesupport (= 6.1.3.2)
|
60
|
+
activestorage (6.1.3.2)
|
61
|
+
actionpack (= 6.1.3.2)
|
62
|
+
activejob (= 6.1.3.2)
|
63
|
+
activerecord (= 6.1.3.2)
|
64
|
+
activesupport (= 6.1.3.2)
|
65
|
+
marcel (~> 1.0.0)
|
66
|
+
mini_mime (~> 1.0.2)
|
67
|
+
activesupport (6.1.3.2)
|
81
68
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
82
|
-
connection_pool (>= 2.2.5)
|
83
|
-
drb
|
84
69
|
i18n (>= 1.6, < 2)
|
85
70
|
minitest (>= 5.1)
|
86
|
-
mutex_m
|
87
71
|
tzinfo (~> 2.0)
|
72
|
+
zeitwerk (~> 2.3)
|
88
73
|
ast (2.4.2)
|
89
|
-
base64 (0.2.0)
|
90
|
-
bigdecimal (3.1.6)
|
91
74
|
builder (3.2.4)
|
92
|
-
cable_ready (
|
75
|
+
cable_ready (5.0.0.pre0)
|
93
76
|
rails (>= 5.2)
|
94
77
|
thread-local (>= 1.1.0)
|
95
78
|
coderay (1.1.3)
|
96
|
-
concurrent-ruby (1.
|
97
|
-
connection_pool (2.4.1)
|
79
|
+
concurrent-ruby (1.1.8)
|
98
80
|
crass (1.0.6)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
activesupport (>= 6.1)
|
104
|
-
i18n (1.14.4)
|
81
|
+
erubi (1.10.0)
|
82
|
+
globalid (0.4.2)
|
83
|
+
activesupport (>= 4.2.0)
|
84
|
+
i18n (1.8.10)
|
105
85
|
concurrent-ruby (~> 1.0)
|
106
|
-
|
107
|
-
irb (1.12.0)
|
108
|
-
rdoc
|
109
|
-
reline (>= 0.4.2)
|
110
|
-
loofah (2.22.0)
|
86
|
+
loofah (2.9.1)
|
111
87
|
crass (~> 1.0.2)
|
112
|
-
nokogiri (>= 1.
|
113
|
-
mail (2.
|
88
|
+
nokogiri (>= 1.5.9)
|
89
|
+
mail (2.7.1)
|
114
90
|
mini_mime (>= 0.1.1)
|
115
|
-
|
116
|
-
net-pop
|
117
|
-
net-smtp
|
118
|
-
marcel (1.0.4)
|
91
|
+
marcel (1.0.1)
|
119
92
|
method_source (0.9.2)
|
120
|
-
mini_mime (1.
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
net-imap (0.4.10)
|
125
|
-
date
|
126
|
-
net-protocol
|
127
|
-
net-pop (0.1.2)
|
128
|
-
net-protocol
|
129
|
-
net-protocol (0.2.2)
|
130
|
-
timeout
|
131
|
-
net-smtp (0.4.0.1)
|
132
|
-
net-protocol
|
133
|
-
nio4r (2.7.0)
|
134
|
-
nokogiri (1.16.2)
|
135
|
-
mini_portile2 (~> 2.8.2)
|
93
|
+
mini_mime (1.0.3)
|
94
|
+
minitest (5.14.4)
|
95
|
+
nio4r (2.5.7)
|
96
|
+
nokogiri (1.11.5-arm64-darwin)
|
136
97
|
racc (~> 1.4)
|
137
98
|
parallel (1.20.1)
|
138
|
-
parser (3.0.
|
99
|
+
parser (3.0.1.1)
|
139
100
|
ast (~> 2.4.1)
|
140
101
|
pry (0.12.2)
|
141
102
|
coderay (~> 1.1.0)
|
142
103
|
method_source (~> 0.9.0)
|
143
104
|
pry-nav (0.3.0)
|
144
105
|
pry (>= 0.9.10, < 0.13.0)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
actiontext (= 7.1.3.2)
|
162
|
-
actionview (= 7.1.3.2)
|
163
|
-
activejob (= 7.1.3.2)
|
164
|
-
activemodel (= 7.1.3.2)
|
165
|
-
activerecord (= 7.1.3.2)
|
166
|
-
activestorage (= 7.1.3.2)
|
167
|
-
activesupport (= 7.1.3.2)
|
106
|
+
racc (1.5.2)
|
107
|
+
rack (2.2.3)
|
108
|
+
rack-test (1.1.0)
|
109
|
+
rack (>= 1.0, < 3)
|
110
|
+
rails (6.1.3.2)
|
111
|
+
actioncable (= 6.1.3.2)
|
112
|
+
actionmailbox (= 6.1.3.2)
|
113
|
+
actionmailer (= 6.1.3.2)
|
114
|
+
actionpack (= 6.1.3.2)
|
115
|
+
actiontext (= 6.1.3.2)
|
116
|
+
actionview (= 6.1.3.2)
|
117
|
+
activejob (= 6.1.3.2)
|
118
|
+
activemodel (= 6.1.3.2)
|
119
|
+
activerecord (= 6.1.3.2)
|
120
|
+
activestorage (= 6.1.3.2)
|
121
|
+
activesupport (= 6.1.3.2)
|
168
122
|
bundler (>= 1.15.0)
|
169
|
-
railties (=
|
170
|
-
|
171
|
-
|
172
|
-
|
123
|
+
railties (= 6.1.3.2)
|
124
|
+
sprockets-rails (>= 2.0.0)
|
125
|
+
rails-dom-testing (2.0.3)
|
126
|
+
activesupport (>= 4.2.0)
|
173
127
|
nokogiri (>= 1.6)
|
174
|
-
rails-html-sanitizer (1.
|
175
|
-
loofah (~> 2.
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
rake (>= 12.2)
|
183
|
-
thor (~> 1.0, >= 1.2.2)
|
184
|
-
zeitwerk (~> 2.6)
|
128
|
+
rails-html-sanitizer (1.3.0)
|
129
|
+
loofah (~> 2.3)
|
130
|
+
railties (6.1.3.2)
|
131
|
+
actionpack (= 6.1.3.2)
|
132
|
+
activesupport (= 6.1.3.2)
|
133
|
+
method_source
|
134
|
+
rake (>= 0.8.7)
|
135
|
+
thor (~> 1.0)
|
185
136
|
rainbow (3.0.0)
|
186
137
|
rake (13.0.3)
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
redis-client (0.21.0)
|
192
|
-
connection_pool
|
193
|
-
regexp_parser (2.0.3)
|
194
|
-
reline (0.4.3)
|
195
|
-
io-console (~> 0.5)
|
196
|
-
rexml (3.2.4)
|
197
|
-
rubocop (1.7.0)
|
138
|
+
redis (4.2.5)
|
139
|
+
regexp_parser (2.1.1)
|
140
|
+
rexml (3.2.5)
|
141
|
+
rubocop (1.14.0)
|
198
142
|
parallel (~> 1.10)
|
199
|
-
parser (>=
|
143
|
+
parser (>= 3.0.0.0)
|
200
144
|
rainbow (>= 2.2.2, < 4.0)
|
201
145
|
regexp_parser (>= 1.8, < 3.0)
|
202
146
|
rexml
|
203
|
-
rubocop-ast (>= 1.
|
147
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
204
148
|
ruby-progressbar (~> 1.7)
|
205
|
-
unicode-display_width (>= 1.4.0, <
|
206
|
-
rubocop-ast (1.
|
207
|
-
parser (>=
|
208
|
-
rubocop-performance (1.
|
209
|
-
rubocop (>=
|
149
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
150
|
+
rubocop-ast (1.5.0)
|
151
|
+
parser (>= 3.0.1.1)
|
152
|
+
rubocop-performance (1.11.2)
|
153
|
+
rubocop (>= 1.7.0, < 2.0)
|
210
154
|
rubocop-ast (>= 0.4.0)
|
211
155
|
ruby-progressbar (1.11.0)
|
212
|
-
|
213
|
-
|
214
|
-
|
156
|
+
sprockets (4.0.2)
|
157
|
+
concurrent-ruby (~> 1.0)
|
158
|
+
rack (> 1, < 3)
|
159
|
+
sprockets-rails (3.2.2)
|
160
|
+
actionpack (>= 4.0)
|
161
|
+
activesupport (>= 4.0)
|
162
|
+
sprockets (>= 3.0.0)
|
163
|
+
standard (1.1.1)
|
164
|
+
rubocop (= 1.14.0)
|
165
|
+
rubocop-performance (= 1.11.2)
|
215
166
|
standardrb (1.0.0)
|
216
167
|
standard
|
217
|
-
|
218
|
-
thor (1.3.1)
|
168
|
+
thor (1.1.0)
|
219
169
|
thread-local (1.1.0)
|
220
|
-
|
221
|
-
tzinfo (2.0.6)
|
170
|
+
tzinfo (2.0.4)
|
222
171
|
concurrent-ruby (~> 1.0)
|
223
|
-
unicode-display_width (
|
224
|
-
|
225
|
-
websocket-driver (0.7.6)
|
172
|
+
unicode-display_width (2.0.0)
|
173
|
+
websocket-driver (0.7.3)
|
226
174
|
websocket-extensions (>= 0.1.0)
|
227
175
|
websocket-extensions (0.1.5)
|
228
|
-
zeitwerk (2.
|
176
|
+
zeitwerk (2.4.2)
|
229
177
|
|
230
178
|
PLATFORMS
|
231
179
|
ruby
|
@@ -235,8 +183,8 @@ DEPENDENCIES
|
|
235
183
|
pry
|
236
184
|
pry-nav
|
237
185
|
rake
|
238
|
-
standardrb
|
186
|
+
standardrb (~> 1.0)
|
239
187
|
stimulus_reflex!
|
240
188
|
|
241
189
|
BUNDLED WITH
|
242
|
-
2.2.
|
190
|
+
2.2.4
|
data/LATEST
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.4.1
|
data/README.md
CHANGED
@@ -7,11 +7,11 @@
|
|
7
7
|
<a href="https://www.npmjs.com/package/stimulus_reflex">
|
8
8
|
<img alt="downloads" src="https://img.shields.io/npm/dm/stimulus_reflex.svg?color=blue" target="_blank" />
|
9
9
|
</a>
|
10
|
-
<a href="https://github.com/
|
10
|
+
<a href="https://github.com/stimulusreflex/stimulus_reflex/blob/master/LICENSE">
|
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-2190-brightgreen.svg?style=flat" />
|
15
15
|
</a>
|
16
16
|
<a href="https://docs.stimulusreflex.com/" target="_blank">
|
17
17
|
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
@@ -30,14 +30,14 @@
|
|
30
30
|
<a href="https://www.codacy.com/manual/hopsoft/stimulus_reflex/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hopsoft/stimulus_reflex&utm_campaign=Badge_Grade" target="_blank">
|
31
31
|
<img alt="Code Quality" src="https://app.codacy.com/project/badge/Grade/d1d72a7060f5467b8696884351cf477f"/>
|
32
32
|
</a>
|
33
|
-
<a target="_blank" rel="noopener noreferrer" href="https://github.com/
|
34
|
-
<img src="https://github.com/
|
33
|
+
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/Prettier-Standard/badge.svg">
|
34
|
+
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
|
35
35
|
</a>
|
36
|
-
<a target="_blank" rel="noopener noreferrer" href="https://github.com/
|
37
|
-
<img src="https://github.com/
|
36
|
+
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/StandardRB/badge.svg">
|
37
|
+
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/StandardRB/badge.svg" alt="StandardRB" style="max-width:100%;">
|
38
38
|
</a>
|
39
|
-
<a target="_blank" rel="noopener noreferrer" href="https://github.com/
|
40
|
-
<img src="https://github.com/
|
39
|
+
<a target="_blank" rel="noopener noreferrer" href="https://github.com/stimulusreflex/stimulus_reflex/workflows/Tests/badge.svg">
|
40
|
+
<img src="https://github.com/stimulusreflex/stimulus_reflex/workflows/Tests/badge.svg" alt="Tests">
|
41
41
|
</a>
|
42
42
|
</p>
|
43
43
|
</p>
|
@@ -75,7 +75,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
|
|
75
75
|
|
76
76
|
## 👩👩👧 Discord Community
|
77
77
|
|
78
|
-
Please join over 1000 of us on [Discord](https://discord.gg/
|
78
|
+
Please join over 1000 of us on [Discord](https://discord.gg/stimulus-reflex) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
|
79
79
|
|
80
80
|

|
81
81
|
|
@@ -104,7 +104,7 @@ and [Prettier-Standard](https://github.com/sheerun/prettier-standard) for JavaSc
|
|
104
104
|
|
105
105
|
Please run `./bin/standardize` prior to submitting pull requests.
|
106
106
|
|
107
|
-
View the [wiki](https://github.com/
|
107
|
+
View the [wiki](https://github.com/stimulusreflex/stimulus_reflex/wiki/Editor-Configuration) to see recommendations for configuring your editor to work best with the project.
|
108
108
|
|
109
109
|
## 📦 Releasing
|
110
110
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.constantize
|
4
|
+
attr_reader :reflex_data
|
5
|
+
|
4
6
|
def stream_name
|
5
7
|
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
6
8
|
[
|
@@ -11,49 +13,25 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
11
13
|
|
12
14
|
def subscribed
|
13
15
|
super
|
14
|
-
fix_environment!
|
15
16
|
stream_from stream_name
|
16
17
|
end
|
17
18
|
|
18
19
|
def receive(data)
|
19
|
-
|
20
|
-
selectors = (data["selectors"] || []).select(&:present?)
|
21
|
-
selectors = data["selectors"] = ["body"] if selectors.blank?
|
22
|
-
target = data["target"].to_s
|
23
|
-
factory = StimulusReflex::ReflexFactory.new(target)
|
24
|
-
reflex_class = factory.call
|
25
|
-
method_name = factory.method_name
|
26
|
-
arguments = (data["args"] || []).map { |arg| object_with_indifferent_access arg }
|
27
|
-
element = StimulusReflex::Element.new(data)
|
28
|
-
permanent_attribute_name = data["permanentAttributeName"]
|
29
|
-
form_data = Rack::Utils.parse_nested_query(data["formData"])
|
30
|
-
params = form_data.deep_merge(data["params"] || {})
|
31
|
-
|
20
|
+
@reflex_data = StimulusReflex::ReflexData.new(data)
|
32
21
|
begin
|
33
22
|
begin
|
34
|
-
reflex =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
params: params,
|
40
|
-
client_attributes: {
|
41
|
-
reflex_id: data["reflexId"],
|
42
|
-
xpath_controller: data["xpathController"],
|
43
|
-
xpath_element: data["xpathElement"],
|
44
|
-
reflex_controller: data["reflexController"],
|
45
|
-
permanent_attribute_name: permanent_attribute_name
|
46
|
-
})
|
47
|
-
delegate_call_to_reflex reflex, method_name, arguments
|
48
|
-
rescue => invoke_error
|
49
|
-
message = exception_message_with_backtrace(invoke_error)
|
50
|
-
body = "Reflex #{target} failed: #{message} [#{url}]"
|
23
|
+
reflex = StimulusReflex::ReflexFactory.create_reflex_from_data(self, @reflex_data)
|
24
|
+
delegate_call_to_reflex reflex
|
25
|
+
rescue => exception
|
26
|
+
error = exception_with_backtrace(exception)
|
27
|
+
error_message = "\e[31mReflex #{reflex_data.target} failed: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
|
51
28
|
|
52
29
|
if reflex
|
53
|
-
reflex.rescue_with_handler(
|
54
|
-
|
30
|
+
reflex.rescue_with_handler(exception)
|
31
|
+
puts error_message
|
32
|
+
reflex.broadcast_message subject: "error", data: data, error: exception
|
55
33
|
else
|
56
|
-
puts
|
34
|
+
puts error_message
|
57
35
|
|
58
36
|
if body.to_s.include? "No route matches"
|
59
37
|
initializer_path = Rails.root.join("config", "initializers", "stimulus_reflex.rb")
|
@@ -83,39 +61,35 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
83
61
|
reflex.broadcast_message subject: "halted", data: data
|
84
62
|
else
|
85
63
|
begin
|
86
|
-
reflex.broadcast(selectors, data)
|
87
|
-
rescue =>
|
88
|
-
reflex.rescue_with_handler(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
puts "\e[31m#{body}\e[0m"
|
64
|
+
reflex.broadcast(reflex_data.selectors, data)
|
65
|
+
rescue => exception
|
66
|
+
reflex.rescue_with_handler(exception)
|
67
|
+
error = exception_with_backtrace(exception)
|
68
|
+
reflex.broadcast_message subject: "error", data: data, error: exception
|
69
|
+
puts "\e[31mReflex failed to re-render: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
|
93
70
|
end
|
94
71
|
end
|
95
72
|
ensure
|
96
73
|
if reflex
|
97
74
|
commit_session(reflex)
|
98
|
-
reflex.
|
75
|
+
report_failed_basic_auth(reflex) if reflex.controller?
|
76
|
+
reflex.logger&.print
|
99
77
|
end
|
100
78
|
end
|
101
79
|
end
|
102
80
|
|
103
81
|
private
|
104
82
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
object
|
109
|
-
end
|
110
|
-
|
111
|
-
def delegate_call_to_reflex(reflex, method_name, arguments = [])
|
83
|
+
def delegate_call_to_reflex(reflex)
|
84
|
+
method_name = reflex_data.method_name
|
85
|
+
arguments = reflex_data.arguments
|
112
86
|
method = reflex.method(method_name)
|
113
|
-
required_params = method.parameters.select { |(kind, _)| kind == :req }
|
114
|
-
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
115
87
|
|
116
|
-
|
88
|
+
policy = StimulusReflex::ReflexMethodInvocationPolicy.new(method, arguments)
|
89
|
+
|
90
|
+
if policy.no_arguments?
|
117
91
|
reflex.process(method_name)
|
118
|
-
elsif
|
92
|
+
elsif policy.arguments?
|
119
93
|
reflex.process(method_name, *arguments)
|
120
94
|
else
|
121
95
|
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
|
@@ -125,18 +99,22 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
125
99
|
def commit_session(reflex)
|
126
100
|
store = reflex.request.session.instance_variable_get("@by")
|
127
101
|
store.commit_session reflex.request, reflex.controller.response
|
128
|
-
rescue =>
|
129
|
-
|
130
|
-
puts "\e[
|
102
|
+
rescue => exception
|
103
|
+
error = exception_with_backtrace(exception)
|
104
|
+
puts "\e[31mFailed to commit session! #{error[:message]}\e[0m\n#{error[:backtrace]}"
|
131
105
|
end
|
132
106
|
|
133
|
-
def
|
134
|
-
|
107
|
+
def report_failed_basic_auth(reflex)
|
108
|
+
if reflex.controller.response.status == 401
|
109
|
+
puts "\e[31mReflex failed to process controller action \"#{reflex.controller.class}##{reflex.controller.action_name}\" due to HTTP basic auth. Consider adding \"unless: -> { @stimulus_reflex }\" to the before_action or method responible for authentication.\e[0m"
|
110
|
+
end
|
135
111
|
end
|
136
112
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
113
|
+
def exception_with_backtrace(exception)
|
114
|
+
{
|
115
|
+
message: exception.to_s,
|
116
|
+
backtrace: exception.backtrace.first,
|
117
|
+
stack: exception.backtrace.join("\n")
|
118
|
+
}
|
141
119
|
end
|
142
120
|
end
|
data/lib/generators/USAGE
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
require "rails/generators"
|
4
4
|
|
5
5
|
module StimulusReflex
|
6
|
-
class
|
7
|
-
desc "Creates
|
6
|
+
class InitializerGenerator < Rails::Generators::Base
|
7
|
+
desc "Creates a StimulusReflex initializer in config/initializers"
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
|
-
def
|
10
|
+
def copy_initializer_file
|
11
11
|
copy_file "config/initializers/stimulus_reflex.rb"
|
12
12
|
end
|
13
13
|
end
|
@@ -17,12 +17,13 @@ class <%= class_name %>Reflex < ApplicationReflex
|
|
17
17
|
# - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
|
18
18
|
# - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
|
19
19
|
# - reflex_id - a UUIDv4 that uniquely identies each Reflex
|
20
|
+
# - tab_id - a UUIDv4 that uniquely identifies the browser tab
|
20
21
|
#
|
21
22
|
# Example:
|
22
23
|
#
|
23
24
|
# before_reflex do
|
24
25
|
# # throw :abort # this will prevent the Reflex from continuing
|
25
|
-
# # learn more about callbacks at https://docs.stimulusreflex.com/lifecycle
|
26
|
+
# # learn more about callbacks at https://docs.stimulusreflex.com/rtfm/lifecycle
|
26
27
|
# end
|
27
28
|
#
|
28
29
|
# def example(argument=true)
|
@@ -30,7 +31,7 @@ class <%= class_name %>Reflex < ApplicationReflex
|
|
30
31
|
# # Any declared instance variables will be made available to the Rails controller and view.
|
31
32
|
# end
|
32
33
|
#
|
33
|
-
# Learn more at: https://docs.stimulusreflex.com/
|
34
|
+
# Learn more at: https://docs.stimulusreflex.com/rtfm/reflex-classes
|
34
35
|
|
35
36
|
<% actions.each do |action| -%>
|
36
37
|
def <%= action %>
|
@@ -8,5 +8,5 @@ class ApplicationReflex < StimulusReflex::Reflex
|
|
8
8
|
# # If your ActionCable connection is: `identified_by :current_user`
|
9
9
|
# delegate :current_user, to: :connection
|
10
10
|
#
|
11
|
-
# Learn more at: https://docs.stimulusreflex.com/
|
11
|
+
# Learn more at: https://docs.stimulusreflex.com/rtfm/reflex-classes
|
12
12
|
end
|
@@ -6,6 +6,11 @@ StimulusReflex.configure do |config|
|
|
6
6
|
|
7
7
|
# config.on_failed_sanity_checks = :exit
|
8
8
|
|
9
|
+
# Enable/disable exiting / warning when there's a new StimulusReflex release
|
10
|
+
# `:exit` or `:warn` or `:ignore`
|
11
|
+
|
12
|
+
# config.on_new_version_available = :ignore
|
13
|
+
|
9
14
|
# Override the parent class that the StimulusReflex ActionCable channel inherits from
|
10
15
|
|
11
16
|
# config.parent_channel = "ApplicationCable::Channel"
|
@@ -15,7 +20,7 @@ StimulusReflex.configure do |config|
|
|
15
20
|
# Available colors: red, green, yellow, blue, magenta, cyan, white
|
16
21
|
# You can also use attributes from your ActionCable Connection's identifiers that resolve to valid ActiveRecord models
|
17
22
|
# eg. if your connection is `identified_by :current_user` and your User model has an email attribute, you can access r.email (it will display `-` if the user isn't logged in)
|
18
|
-
# Learn more at: https://docs.stimulusreflex.com/troubleshooting#stimulusreflex-logging
|
23
|
+
# Learn more at: https://docs.stimulusreflex.com/appendices/troubleshooting#stimulusreflex-logging
|
19
24
|
|
20
25
|
# config.logging = proc { "[#{session_id}] #{operation_counter.magenta} #{reflex_info.green} -> #{selector.cyan} via #{mode} Morph (#{operation.yellow})" }
|
21
26
|
|