stimulus_reflex 3.4.0.pre8 → 3.5.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +639 -463
- data/CODE_OF_CONDUCT.md +6 -0
- data/Gemfile.lock +103 -100
- data/LATEST +1 -0
- data/README.md +14 -13
- data/app/channels/stimulus_reflex/channel.rb +62 -67
- 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 +14 -0
- data/lib/stimulus_reflex.rb +11 -3
- 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 +30 -6
- data/lib/stimulus_reflex/callbacks.rb +98 -0
- data/lib/stimulus_reflex/concern_enhancer.rb +37 -0
- data/lib/stimulus_reflex/configuration.rb +3 -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 +57 -57
- data/lib/stimulus_reflex/reflex_data.rb +79 -0
- data/lib/stimulus_reflex/reflex_factory.rb +31 -0
- data/lib/stimulus_reflex/request_parameters.rb +19 -0
- data/lib/stimulus_reflex/{logger.rb → utils/logger.rb} +6 -8
- data/lib/stimulus_reflex/{sanity_checker.rb → utils/sanity_checker.rb} +65 -10
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +14 -7
- data/test/broadcasters/broadcaster_test.rb +2 -0
- data/test/broadcasters/broadcaster_test_case.rb +3 -1
- data/test/broadcasters/nothing_broadcaster_test.rb +7 -3
- data/test/broadcasters/page_broadcaster_test.rb +10 -4
- data/test/broadcasters/selector_broadcaster_test.rb +173 -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 +7 -1
- data/test/test_helper.rb +10 -0
- data/test/tmp/app/reflexes/application_reflex.rb +1 -1
- data/test/tmp/app/reflexes/demo_reflex.rb +3 -2
- metadata +45 -36
- data/package.json +0 -57
- data/stimulus_reflex.gemspec +0 -40
- data/tags +0 -139
- data/yarn.lock +0 -4711
data/CODE_OF_CONDUCT.md
CHANGED
@@ -61,6 +61,12 @@ is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
62
|
Further details of specific enforcement policies may be posted separately.
|
63
63
|
|
64
|
+
### General Policy
|
65
|
+
|
66
|
+
- 1st offense - user will be warned that they violated the CoC
|
67
|
+
- 2nd offense - user will be publicly flagged as a CoC violator
|
68
|
+
- 3rd offense - user will be banned from the community
|
69
|
+
|
64
70
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
71
|
faith may face temporary or permanent repercussions as determined by other
|
66
72
|
members of the project's leadership.
|
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.pre1)
|
5
|
+
cable_ready (= 5.0.0.pre1)
|
6
6
|
nokogiri
|
7
7
|
rack
|
8
8
|
rails (>= 5.2)
|
@@ -11,145 +11,148 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
actioncable (6.
|
15
|
-
actionpack (= 6.
|
14
|
+
actioncable (6.1.3.2)
|
15
|
+
actionpack (= 6.1.3.2)
|
16
|
+
activesupport (= 6.1.3.2)
|
16
17
|
nio4r (~> 2.0)
|
17
18
|
websocket-driver (>= 0.6.1)
|
18
|
-
actionmailbox (6.
|
19
|
-
actionpack (= 6.
|
20
|
-
activejob (= 6.
|
21
|
-
activerecord (= 6.
|
22
|
-
activestorage (= 6.
|
23
|
-
activesupport (= 6.
|
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)
|
24
25
|
mail (>= 2.7.1)
|
25
|
-
actionmailer (6.
|
26
|
-
actionpack (= 6.
|
27
|
-
actionview (= 6.
|
28
|
-
activejob (= 6.
|
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)
|
29
31
|
mail (~> 2.5, >= 2.5.4)
|
30
32
|
rails-dom-testing (~> 2.0)
|
31
|
-
actionpack (6.
|
32
|
-
actionview (= 6.
|
33
|
-
activesupport (= 6.
|
34
|
-
rack (~> 2.0, >= 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)
|
35
37
|
rack-test (>= 0.6.3)
|
36
38
|
rails-dom-testing (~> 2.0)
|
37
39
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
-
actiontext (6.
|
39
|
-
actionpack (= 6.
|
40
|
-
activerecord (= 6.
|
41
|
-
activestorage (= 6.
|
42
|
-
activesupport (= 6.
|
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)
|
43
45
|
nokogiri (>= 1.8.5)
|
44
|
-
actionview (6.
|
45
|
-
activesupport (= 6.
|
46
|
+
actionview (6.1.3.2)
|
47
|
+
activesupport (= 6.1.3.2)
|
46
48
|
builder (~> 3.1)
|
47
49
|
erubi (~> 1.4)
|
48
50
|
rails-dom-testing (~> 2.0)
|
49
51
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
-
activejob (6.
|
51
|
-
activesupport (= 6.
|
52
|
+
activejob (6.1.3.2)
|
53
|
+
activesupport (= 6.1.3.2)
|
52
54
|
globalid (>= 0.3.6)
|
53
|
-
activemodel (6.
|
54
|
-
activesupport (= 6.
|
55
|
-
activerecord (6.
|
56
|
-
activemodel (= 6.
|
57
|
-
activesupport (= 6.
|
58
|
-
activestorage (6.
|
59
|
-
actionpack (= 6.
|
60
|
-
activejob (= 6.
|
61
|
-
activerecord (= 6.
|
62
|
-
|
63
|
-
|
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)
|
64
68
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
|
-
i18n (>=
|
66
|
-
minitest (
|
67
|
-
tzinfo (~>
|
68
|
-
zeitwerk (~> 2.
|
69
|
-
ast (2.4.
|
69
|
+
i18n (>= 1.6, < 2)
|
70
|
+
minitest (>= 5.1)
|
71
|
+
tzinfo (~> 2.0)
|
72
|
+
zeitwerk (~> 2.3)
|
73
|
+
ast (2.4.2)
|
70
74
|
builder (3.2.4)
|
71
|
-
cable_ready (
|
75
|
+
cable_ready (5.0.0.pre1)
|
72
76
|
rails (>= 5.2)
|
77
|
+
thread-local (>= 1.1.0)
|
73
78
|
coderay (1.1.3)
|
74
|
-
concurrent-ruby (1.1.
|
79
|
+
concurrent-ruby (1.1.8)
|
75
80
|
crass (1.0.6)
|
76
81
|
erubi (1.10.0)
|
77
82
|
globalid (0.4.2)
|
78
83
|
activesupport (>= 4.2.0)
|
79
|
-
i18n (1.8.
|
84
|
+
i18n (1.8.10)
|
80
85
|
concurrent-ruby (~> 1.0)
|
81
|
-
loofah (2.
|
86
|
+
loofah (2.9.1)
|
82
87
|
crass (~> 1.0.2)
|
83
88
|
nokogiri (>= 1.5.9)
|
84
89
|
mail (2.7.1)
|
85
90
|
mini_mime (>= 0.1.1)
|
86
|
-
marcel (0.
|
87
|
-
mimemagic (~> 0.3.2)
|
91
|
+
marcel (1.0.1)
|
88
92
|
method_source (0.9.2)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
nokogiri (1.10.10)
|
95
|
-
mini_portile2 (~> 2.4.0)
|
93
|
+
mini_mime (1.0.3)
|
94
|
+
minitest (5.14.4)
|
95
|
+
nio4r (2.5.7)
|
96
|
+
nokogiri (1.11.6-x86_64-linux)
|
97
|
+
racc (~> 1.4)
|
96
98
|
parallel (1.20.1)
|
97
|
-
parser (
|
99
|
+
parser (3.0.1.1)
|
98
100
|
ast (~> 2.4.1)
|
99
101
|
pry (0.12.2)
|
100
102
|
coderay (~> 1.1.0)
|
101
103
|
method_source (~> 0.9.0)
|
102
104
|
pry-nav (0.3.0)
|
103
105
|
pry (>= 0.9.10, < 0.13.0)
|
106
|
+
racc (1.5.2)
|
104
107
|
rack (2.2.3)
|
105
108
|
rack-test (1.1.0)
|
106
109
|
rack (>= 1.0, < 3)
|
107
|
-
rails (6.
|
108
|
-
actioncable (= 6.
|
109
|
-
actionmailbox (= 6.
|
110
|
-
actionmailer (= 6.
|
111
|
-
actionpack (= 6.
|
112
|
-
actiontext (= 6.
|
113
|
-
actionview (= 6.
|
114
|
-
activejob (= 6.
|
115
|
-
activemodel (= 6.
|
116
|
-
activerecord (= 6.
|
117
|
-
activestorage (= 6.
|
118
|
-
activesupport (= 6.
|
119
|
-
bundler (>= 1.
|
120
|
-
railties (= 6.
|
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)
|
122
|
+
bundler (>= 1.15.0)
|
123
|
+
railties (= 6.1.3.2)
|
121
124
|
sprockets-rails (>= 2.0.0)
|
122
125
|
rails-dom-testing (2.0.3)
|
123
126
|
activesupport (>= 4.2.0)
|
124
127
|
nokogiri (>= 1.6)
|
125
128
|
rails-html-sanitizer (1.3.0)
|
126
129
|
loofah (~> 2.3)
|
127
|
-
railties (6.
|
128
|
-
actionpack (= 6.
|
129
|
-
activesupport (= 6.
|
130
|
+
railties (6.1.3.2)
|
131
|
+
actionpack (= 6.1.3.2)
|
132
|
+
activesupport (= 6.1.3.2)
|
130
133
|
method_source
|
131
134
|
rake (>= 0.8.7)
|
132
|
-
thor (
|
135
|
+
thor (~> 1.0)
|
133
136
|
rainbow (3.0.0)
|
134
|
-
rake (13.0.
|
137
|
+
rake (13.0.3)
|
135
138
|
redis (4.2.5)
|
136
|
-
regexp_parser (2.
|
137
|
-
rexml (3.2.
|
138
|
-
rubocop (1.
|
139
|
+
regexp_parser (2.1.1)
|
140
|
+
rexml (3.2.5)
|
141
|
+
rubocop (1.14.0)
|
139
142
|
parallel (~> 1.10)
|
140
|
-
parser (>=
|
143
|
+
parser (>= 3.0.0.0)
|
141
144
|
rainbow (>= 2.2.2, < 4.0)
|
142
|
-
regexp_parser (>= 1.8)
|
145
|
+
regexp_parser (>= 1.8, < 3.0)
|
143
146
|
rexml
|
144
|
-
rubocop-ast (>= 1.
|
147
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
145
148
|
ruby-progressbar (~> 1.7)
|
146
|
-
unicode-display_width (>= 1.4.0, <
|
147
|
-
rubocop-ast (1.
|
148
|
-
parser (>=
|
149
|
-
rubocop-performance (1.
|
150
|
-
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)
|
151
154
|
rubocop-ast (>= 0.4.0)
|
152
|
-
ruby-progressbar (1.
|
155
|
+
ruby-progressbar (1.11.0)
|
153
156
|
sprockets (4.0.2)
|
154
157
|
concurrent-ruby (~> 1.0)
|
155
158
|
rack (> 1, < 3)
|
@@ -157,31 +160,31 @@ GEM
|
|
157
160
|
actionpack (>= 4.0)
|
158
161
|
activesupport (>= 4.0)
|
159
162
|
sprockets (>= 3.0.0)
|
160
|
-
standard (
|
161
|
-
rubocop (= 1.
|
162
|
-
rubocop-performance (= 1.
|
163
|
+
standard (1.1.1)
|
164
|
+
rubocop (= 1.14.0)
|
165
|
+
rubocop-performance (= 1.11.2)
|
163
166
|
standardrb (1.0.0)
|
164
167
|
standard
|
165
|
-
thor (1.0
|
166
|
-
|
167
|
-
tzinfo (
|
168
|
-
|
169
|
-
unicode-display_width (
|
170
|
-
websocket-driver (0.7.
|
168
|
+
thor (1.1.0)
|
169
|
+
thread-local (1.1.0)
|
170
|
+
tzinfo (2.0.4)
|
171
|
+
concurrent-ruby (~> 1.0)
|
172
|
+
unicode-display_width (2.0.0)
|
173
|
+
websocket-driver (0.7.4)
|
171
174
|
websocket-extensions (>= 0.1.0)
|
172
175
|
websocket-extensions (0.1.5)
|
173
176
|
zeitwerk (2.4.2)
|
174
177
|
|
175
178
|
PLATFORMS
|
176
|
-
|
179
|
+
x86_64-linux
|
177
180
|
|
178
181
|
DEPENDENCIES
|
179
182
|
bundler (~> 2.0)
|
180
183
|
pry
|
181
184
|
pry-nav
|
182
185
|
rake
|
183
|
-
standardrb
|
186
|
+
standardrb (~> 1.0)
|
184
187
|
stimulus_reflex!
|
185
188
|
|
186
189
|
BUNDLED WITH
|
187
|
-
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>
|
@@ -65,6 +65,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
|
|
65
65
|
|
66
66
|
- [StimulusReflex Documentation](https://docs.stimulusreflex.com)
|
67
67
|
- [CableReady Documentation](https://cableready.stimulusreflex.com)
|
68
|
+
- [StimulusReflex Cheatsheet](https://devhints.io/stimulus-reflex)
|
68
69
|
|
69
70
|
## ✨ Demos
|
70
71
|
|
@@ -74,7 +75,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
|
|
74
75
|
|
75
76
|
## 👩👩👧 Discord Community
|
76
77
|
|
77
|
-
Please join over
|
78
|
+
Please join over 1300 of us on [Discord](https://discord.gg/stimulus-reflex) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
|
78
79
|
|
79
80
|
![](https://img.shields.io/discord/629472241427415060)
|
80
81
|
|
@@ -82,13 +83,13 @@ Stop by #newcomers and introduce yourselves!
|
|
82
83
|
|
83
84
|
## 💙 Support
|
84
85
|
|
85
|
-
Your best bet is to ask for help on Discord before filing an issue on Github. We are happy to help, and we ask people to come with all relevant code to look at. A git repo is preferred, but Gists
|
86
|
+
Your best bet is to ask for help on Discord before filing an issue on Github. We are happy to help, and we ask people who need help to come with all relevant code to look at. A git repo is preferred, but Gists are fine, too. If you need an MVCE template, try [this](https://github.com/leastbad/stimulus_reflex_harness).
|
86
87
|
|
87
88
|
Please note that we are not actively providing support on Stack Overflow. If you post there, we likely won't see it.
|
88
89
|
|
89
|
-
## 🚀
|
90
|
+
## 🚀 Installation and upgrading
|
90
91
|
|
91
|
-
CLI and manual setup procedures are fully detailed in the [official docs](https://docs.stimulusreflex.com/setup).
|
92
|
+
CLI and manual setup procedures are fully detailed in the [official docs](https://docs.stimulusreflex.com/setup). For information on upgrading existing projects to v3.4, read [this](https://docs.stimulusreflex.com/setup#upgrading-to-v-3-4-0).
|
92
93
|
|
93
94
|
## 🙏 Contributing
|
94
95
|
|
@@ -103,7 +104,7 @@ and [Prettier-Standard](https://github.com/sheerun/prettier-standard) for JavaSc
|
|
103
104
|
|
104
105
|
Please run `./bin/standardize` prior to submitting pull requests.
|
105
106
|
|
106
|
-
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.
|
107
108
|
|
108
109
|
## 📦 Releasing
|
109
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,46 @@ 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
|
-
reflex_name, method_name = target.split("#")
|
24
|
-
reflex_name = reflex_name.camelize
|
25
|
-
reflex_name = reflex_name.end_with?("Reflex") ? reflex_name : "#{reflex_name}Reflex"
|
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
|
-
|
35
|
-
reflex
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
params: params,
|
41
|
-
client_attributes: {
|
42
|
-
reflex_id: data["reflexId"],
|
43
|
-
xpath: data["xpath"],
|
44
|
-
c_xpath: data["cXpath"],
|
45
|
-
reflex_controller: data["reflexController"],
|
46
|
-
permanent_attribute_name: permanent_attribute_name
|
47
|
-
})
|
48
|
-
delegate_call_to_reflex reflex, method_name, arguments
|
49
|
-
rescue => invoke_error
|
50
|
-
message = exception_message_with_backtrace(invoke_error)
|
51
|
-
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]}"
|
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
|
35
|
+
|
36
|
+
if body.to_s.include? "No route matches"
|
37
|
+
initializer_path = Rails.root.join("config", "initializers", "stimulus_reflex.rb")
|
38
|
+
|
39
|
+
puts <<~NOTE
|
40
|
+
\e[33mNOTE: StimulusReflex failed to locate a matching route and could not re-render the page.
|
41
|
+
|
42
|
+
If your app uses Rack middleware to rewrite part of the request path, you must enable those middleware modules in StimulusReflex.
|
43
|
+
The StimulusReflex initializer should be located at #{initializer_path}, or you can generate it with:
|
44
|
+
|
45
|
+
$ bundle exec rails generate stimulus_reflex:config
|
46
|
+
|
47
|
+
Configure any required middleware:
|
48
|
+
|
49
|
+
StimulusReflex.configure do |config|
|
50
|
+
config.middleware.use FirstRackMiddleware
|
51
|
+
config.middleware.use SecondRackMiddleware
|
52
|
+
end\e[0m
|
53
|
+
|
54
|
+
NOTE
|
55
|
+
end
|
57
56
|
end
|
58
57
|
return
|
59
58
|
end
|
@@ -62,43 +61,35 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
62
61
|
reflex.broadcast_message subject: "halted", data: data
|
63
62
|
else
|
64
63
|
begin
|
65
|
-
reflex.broadcast(selectors, data)
|
66
|
-
rescue =>
|
67
|
-
reflex.rescue_with_handler(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
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]}"
|
72
70
|
end
|
73
71
|
end
|
74
72
|
ensure
|
75
73
|
if reflex
|
76
74
|
commit_session(reflex)
|
77
|
-
reflex.
|
75
|
+
report_failed_basic_auth(reflex) if reflex.controller?
|
76
|
+
reflex.logger&.print
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
private
|
83
82
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
object
|
88
|
-
end
|
89
|
-
|
90
|
-
def is_reflex?(reflex_class)
|
91
|
-
reflex_class.ancestors.include? StimulusReflex::Reflex
|
92
|
-
end
|
93
|
-
|
94
|
-
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
|
95
86
|
method = reflex.method(method_name)
|
96
|
-
required_params = method.parameters.select { |(kind, _)| kind == :req }
|
97
|
-
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
98
87
|
|
99
|
-
|
88
|
+
policy = StimulusReflex::ReflexMethodInvocationPolicy.new(method, arguments)
|
89
|
+
|
90
|
+
if policy.no_arguments?
|
100
91
|
reflex.process(method_name)
|
101
|
-
elsif
|
92
|
+
elsif policy.arguments?
|
102
93
|
reflex.process(method_name, *arguments)
|
103
94
|
else
|
104
95
|
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
|
@@ -108,18 +99,22 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
108
99
|
def commit_session(reflex)
|
109
100
|
store = reflex.request.session.instance_variable_get("@by")
|
110
101
|
store.commit_session reflex.request, reflex.controller.response
|
111
|
-
rescue =>
|
112
|
-
|
113
|
-
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]}"
|
114
105
|
end
|
115
106
|
|
116
|
-
def
|
117
|
-
|
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
|
118
111
|
end
|
119
112
|
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
|
113
|
+
def exception_with_backtrace(exception)
|
114
|
+
{
|
115
|
+
message: exception.to_s,
|
116
|
+
backtrace: exception.backtrace.first,
|
117
|
+
stack: exception.backtrace.join("\n")
|
118
|
+
}
|
124
119
|
end
|
125
120
|
end
|