stimulus_reflex 3.4.0 → 3.5.0.pre2
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 +639 -484
- data/CODE_OF_CONDUCT.md +6 -0
- data/Gemfile.lock +99 -96
- data/LATEST +1 -0
- data/README.md +15 -14
- data/app/channels/stimulus_reflex/channel.rb +42 -73
- 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 +11 -4
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +16 -1
- data/lib/stimulus_reflex.rb +11 -2
- 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 +20 -10
- data/lib/stimulus_reflex/broadcasters/update.rb +23 -0
- data/lib/stimulus_reflex/cable_ready_channels.rb +18 -3
- 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 +48 -7
- data/lib/stimulus_reflex/policies/reflex_invocation_policy.rb +28 -0
- data/lib/stimulus_reflex/reflex.rb +49 -58
- 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/utils/sanity_checker.rb +210 -0
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +54 -15
- data/package.json +7 -6
- data/stimulus_reflex.gemspec +8 -8
- 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 +2 -2
- data/test/test_helper.rb +22 -0
- data/test/tmp/app/reflexes/application_reflex.rb +10 -3
- data/test/tmp/app/reflexes/demo_reflex.rb +4 -2
- data/yarn.lock +1280 -1284
- metadata +47 -33
- data/lib/stimulus_reflex/sanity_checker.rb +0 -154
- data/tags +0 -156
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.pre2)
|
5
|
+
cable_ready (= 5.0.0.pre2)
|
6
6
|
nokogiri
|
7
7
|
rack
|
8
8
|
rails (>= 5.2)
|
@@ -11,149 +11,150 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
actioncable (6.1.
|
15
|
-
actionpack (= 6.1.
|
16
|
-
activesupport (= 6.1.
|
14
|
+
actioncable (6.1.4)
|
15
|
+
actionpack (= 6.1.4)
|
16
|
+
activesupport (= 6.1.4)
|
17
17
|
nio4r (~> 2.0)
|
18
18
|
websocket-driver (>= 0.6.1)
|
19
|
-
actionmailbox (6.1.
|
20
|
-
actionpack (= 6.1.
|
21
|
-
activejob (= 6.1.
|
22
|
-
activerecord (= 6.1.
|
23
|
-
activestorage (= 6.1.
|
24
|
-
activesupport (= 6.1.
|
19
|
+
actionmailbox (6.1.4)
|
20
|
+
actionpack (= 6.1.4)
|
21
|
+
activejob (= 6.1.4)
|
22
|
+
activerecord (= 6.1.4)
|
23
|
+
activestorage (= 6.1.4)
|
24
|
+
activesupport (= 6.1.4)
|
25
25
|
mail (>= 2.7.1)
|
26
|
-
actionmailer (6.1.
|
27
|
-
actionpack (= 6.1.
|
28
|
-
actionview (= 6.1.
|
29
|
-
activejob (= 6.1.
|
30
|
-
activesupport (= 6.1.
|
26
|
+
actionmailer (6.1.4)
|
27
|
+
actionpack (= 6.1.4)
|
28
|
+
actionview (= 6.1.4)
|
29
|
+
activejob (= 6.1.4)
|
30
|
+
activesupport (= 6.1.4)
|
31
31
|
mail (~> 2.5, >= 2.5.4)
|
32
32
|
rails-dom-testing (~> 2.0)
|
33
|
-
actionpack (6.1.
|
34
|
-
actionview (= 6.1.
|
35
|
-
activesupport (= 6.1.
|
33
|
+
actionpack (6.1.4)
|
34
|
+
actionview (= 6.1.4)
|
35
|
+
activesupport (= 6.1.4)
|
36
36
|
rack (~> 2.0, >= 2.0.9)
|
37
37
|
rack-test (>= 0.6.3)
|
38
38
|
rails-dom-testing (~> 2.0)
|
39
39
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
40
|
-
actiontext (6.1.
|
41
|
-
actionpack (= 6.1.
|
42
|
-
activerecord (= 6.1.
|
43
|
-
activestorage (= 6.1.
|
44
|
-
activesupport (= 6.1.
|
40
|
+
actiontext (6.1.4)
|
41
|
+
actionpack (= 6.1.4)
|
42
|
+
activerecord (= 6.1.4)
|
43
|
+
activestorage (= 6.1.4)
|
44
|
+
activesupport (= 6.1.4)
|
45
45
|
nokogiri (>= 1.8.5)
|
46
|
-
actionview (6.1.
|
47
|
-
activesupport (= 6.1.
|
46
|
+
actionview (6.1.4)
|
47
|
+
activesupport (= 6.1.4)
|
48
48
|
builder (~> 3.1)
|
49
49
|
erubi (~> 1.4)
|
50
50
|
rails-dom-testing (~> 2.0)
|
51
51
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
52
|
-
activejob (6.1.
|
53
|
-
activesupport (= 6.1.
|
52
|
+
activejob (6.1.4)
|
53
|
+
activesupport (= 6.1.4)
|
54
54
|
globalid (>= 0.3.6)
|
55
|
-
activemodel (6.1.
|
56
|
-
activesupport (= 6.1.
|
57
|
-
activerecord (6.1.
|
58
|
-
activemodel (= 6.1.
|
59
|
-
activesupport (= 6.1.
|
60
|
-
activestorage (6.1.
|
61
|
-
actionpack (= 6.1.
|
62
|
-
activejob (= 6.1.
|
63
|
-
activerecord (= 6.1.
|
64
|
-
activesupport (= 6.1.
|
65
|
-
marcel (~> 0.
|
66
|
-
|
67
|
-
activesupport (6.1.
|
55
|
+
activemodel (6.1.4)
|
56
|
+
activesupport (= 6.1.4)
|
57
|
+
activerecord (6.1.4)
|
58
|
+
activemodel (= 6.1.4)
|
59
|
+
activesupport (= 6.1.4)
|
60
|
+
activestorage (6.1.4)
|
61
|
+
actionpack (= 6.1.4)
|
62
|
+
activejob (= 6.1.4)
|
63
|
+
activerecord (= 6.1.4)
|
64
|
+
activesupport (= 6.1.4)
|
65
|
+
marcel (~> 1.0.0)
|
66
|
+
mini_mime (>= 1.1.0)
|
67
|
+
activesupport (6.1.4)
|
68
68
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
69
69
|
i18n (>= 1.6, < 2)
|
70
70
|
minitest (>= 5.1)
|
71
71
|
tzinfo (~> 2.0)
|
72
72
|
zeitwerk (~> 2.3)
|
73
|
-
ast (2.4.
|
73
|
+
ast (2.4.2)
|
74
74
|
builder (3.2.4)
|
75
|
-
cable_ready (
|
75
|
+
cable_ready (5.0.0.pre2)
|
76
76
|
rails (>= 5.2)
|
77
|
+
thread-local (>= 1.1.0)
|
77
78
|
coderay (1.1.3)
|
78
|
-
concurrent-ruby (1.1.
|
79
|
+
concurrent-ruby (1.1.9)
|
79
80
|
crass (1.0.6)
|
80
81
|
erubi (1.10.0)
|
81
82
|
globalid (0.4.2)
|
82
83
|
activesupport (>= 4.2.0)
|
83
|
-
i18n (1.8.
|
84
|
+
i18n (1.8.10)
|
84
85
|
concurrent-ruby (~> 1.0)
|
85
|
-
loofah (2.
|
86
|
+
loofah (2.10.0)
|
86
87
|
crass (~> 1.0.2)
|
87
88
|
nokogiri (>= 1.5.9)
|
88
89
|
mail (2.7.1)
|
89
90
|
mini_mime (>= 0.1.1)
|
90
|
-
marcel (0.
|
91
|
-
mimemagic (~> 0.3.2)
|
91
|
+
marcel (1.0.1)
|
92
92
|
method_source (0.9.2)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
nokogiri (1.
|
99
|
-
|
93
|
+
mini_mime (1.1.0)
|
94
|
+
minitest (5.14.4)
|
95
|
+
nio4r (2.5.7)
|
96
|
+
nokogiri (1.11.7-arm64-darwin)
|
97
|
+
racc (~> 1.4)
|
98
|
+
nokogiri (1.11.7-x86_64-linux)
|
99
|
+
racc (~> 1.4)
|
100
100
|
parallel (1.20.1)
|
101
|
-
parser (
|
101
|
+
parser (3.0.2.0)
|
102
102
|
ast (~> 2.4.1)
|
103
103
|
pry (0.12.2)
|
104
104
|
coderay (~> 1.1.0)
|
105
105
|
method_source (~> 0.9.0)
|
106
106
|
pry-nav (0.3.0)
|
107
107
|
pry (>= 0.9.10, < 0.13.0)
|
108
|
+
racc (1.5.2)
|
108
109
|
rack (2.2.3)
|
109
110
|
rack-test (1.1.0)
|
110
111
|
rack (>= 1.0, < 3)
|
111
|
-
rails (6.1.
|
112
|
-
actioncable (= 6.1.
|
113
|
-
actionmailbox (= 6.1.
|
114
|
-
actionmailer (= 6.1.
|
115
|
-
actionpack (= 6.1.
|
116
|
-
actiontext (= 6.1.
|
117
|
-
actionview (= 6.1.
|
118
|
-
activejob (= 6.1.
|
119
|
-
activemodel (= 6.1.
|
120
|
-
activerecord (= 6.1.
|
121
|
-
activestorage (= 6.1.
|
122
|
-
activesupport (= 6.1.
|
112
|
+
rails (6.1.4)
|
113
|
+
actioncable (= 6.1.4)
|
114
|
+
actionmailbox (= 6.1.4)
|
115
|
+
actionmailer (= 6.1.4)
|
116
|
+
actionpack (= 6.1.4)
|
117
|
+
actiontext (= 6.1.4)
|
118
|
+
actionview (= 6.1.4)
|
119
|
+
activejob (= 6.1.4)
|
120
|
+
activemodel (= 6.1.4)
|
121
|
+
activerecord (= 6.1.4)
|
122
|
+
activestorage (= 6.1.4)
|
123
|
+
activesupport (= 6.1.4)
|
123
124
|
bundler (>= 1.15.0)
|
124
|
-
railties (= 6.1.
|
125
|
+
railties (= 6.1.4)
|
125
126
|
sprockets-rails (>= 2.0.0)
|
126
127
|
rails-dom-testing (2.0.3)
|
127
128
|
activesupport (>= 4.2.0)
|
128
129
|
nokogiri (>= 1.6)
|
129
130
|
rails-html-sanitizer (1.3.0)
|
130
131
|
loofah (~> 2.3)
|
131
|
-
railties (6.1.
|
132
|
-
actionpack (= 6.1.
|
133
|
-
activesupport (= 6.1.
|
132
|
+
railties (6.1.4)
|
133
|
+
actionpack (= 6.1.4)
|
134
|
+
activesupport (= 6.1.4)
|
134
135
|
method_source
|
135
|
-
rake (>= 0.
|
136
|
+
rake (>= 0.13)
|
136
137
|
thor (~> 1.0)
|
137
138
|
rainbow (3.0.0)
|
138
|
-
rake (13.0.
|
139
|
-
redis (4.
|
140
|
-
regexp_parser (2.
|
141
|
-
rexml (3.2.
|
142
|
-
rubocop (1.
|
139
|
+
rake (13.0.6)
|
140
|
+
redis (4.3.1)
|
141
|
+
regexp_parser (2.1.1)
|
142
|
+
rexml (3.2.5)
|
143
|
+
rubocop (1.18.3)
|
143
144
|
parallel (~> 1.10)
|
144
|
-
parser (>=
|
145
|
+
parser (>= 3.0.0.0)
|
145
146
|
rainbow (>= 2.2.2, < 4.0)
|
146
|
-
regexp_parser (>= 1.8)
|
147
|
+
regexp_parser (>= 1.8, < 3.0)
|
147
148
|
rexml
|
148
|
-
rubocop-ast (>= 1.
|
149
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
149
150
|
ruby-progressbar (~> 1.7)
|
150
|
-
unicode-display_width (>= 1.4.0, <
|
151
|
-
rubocop-ast (1.
|
152
|
-
parser (>=
|
153
|
-
rubocop-performance (1.
|
154
|
-
rubocop (>=
|
151
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
152
|
+
rubocop-ast (1.8.0)
|
153
|
+
parser (>= 3.0.1.1)
|
154
|
+
rubocop-performance (1.11.4)
|
155
|
+
rubocop (>= 1.7.0, < 2.0)
|
155
156
|
rubocop-ast (>= 0.4.0)
|
156
|
-
ruby-progressbar (1.
|
157
|
+
ruby-progressbar (1.11.0)
|
157
158
|
sprockets (4.0.2)
|
158
159
|
concurrent-ruby (~> 1.0)
|
159
160
|
rack (> 1, < 3)
|
@@ -161,30 +162,32 @@ GEM
|
|
161
162
|
actionpack (>= 4.0)
|
162
163
|
activesupport (>= 4.0)
|
163
164
|
sprockets (>= 3.0.0)
|
164
|
-
standard (
|
165
|
-
rubocop (= 1.
|
166
|
-
rubocop-performance (= 1.
|
165
|
+
standard (1.1.5)
|
166
|
+
rubocop (= 1.18.3)
|
167
|
+
rubocop-performance (= 1.11.4)
|
167
168
|
standardrb (1.0.0)
|
168
169
|
standard
|
169
|
-
thor (1.0
|
170
|
+
thor (1.1.0)
|
171
|
+
thread-local (1.1.0)
|
170
172
|
tzinfo (2.0.4)
|
171
173
|
concurrent-ruby (~> 1.0)
|
172
|
-
unicode-display_width (
|
173
|
-
websocket-driver (0.7.
|
174
|
+
unicode-display_width (2.0.0)
|
175
|
+
websocket-driver (0.7.5)
|
174
176
|
websocket-extensions (>= 0.1.0)
|
175
177
|
websocket-extensions (0.1.5)
|
176
178
|
zeitwerk (2.4.2)
|
177
179
|
|
178
180
|
PLATFORMS
|
179
|
-
|
181
|
+
arm64-darwin-20
|
182
|
+
x86_64-linux
|
180
183
|
|
181
184
|
DEPENDENCIES
|
182
185
|
bundler (~> 2.0)
|
183
186
|
pry
|
184
187
|
pry-nav
|
185
188
|
rake
|
186
|
-
standardrb
|
189
|
+
standardrb (~> 1.0)
|
187
190
|
stimulus_reflex!
|
188
191
|
|
189
192
|
BUNDLED WITH
|
190
|
-
2.
|
193
|
+
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
|

|
80
81
|
|
@@ -103,15 +104,15 @@ 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
|
|
110
111
|
1. Bump version number at `lib/stimulus_reflex/version.rb`
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
2. Run `rake build`
|
113
|
+
3. Run `rake release`
|
114
|
+
4. Run `yarn publish --no-git-tag-version`
|
115
|
+
5. Commit and push changes to the `package.json` file
|
115
116
|
|
116
117
|
## 📝 License
|
117
118
|
|
@@ -1,60 +1,33 @@
|
|
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
|
-
|
6
|
-
[
|
7
|
-
params[:channel],
|
8
|
-
ids.select(&:present?).join(";")
|
9
|
-
].select(&:present?).join(":")
|
7
|
+
[params[:channel], connection.connection_identifier].join(":")
|
10
8
|
end
|
11
9
|
|
12
10
|
def subscribed
|
13
11
|
super
|
14
|
-
fix_environment!
|
15
12
|
stream_from stream_name
|
16
13
|
end
|
17
14
|
|
18
15
|
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
|
-
|
16
|
+
@reflex_data = StimulusReflex::ReflexData.new(data)
|
32
17
|
begin
|
33
18
|
begin
|
34
|
-
|
35
|
-
reflex
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
method_name: method_name,
|
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}]"
|
19
|
+
reflex = StimulusReflex::ReflexFactory.create_reflex_from_data(self, @reflex_data)
|
20
|
+
delegate_call_to_reflex reflex
|
21
|
+
rescue => exception
|
22
|
+
error = exception_with_backtrace(exception)
|
23
|
+
error_message = "\e[31mReflex #{reflex_data.target} failed: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
|
52
24
|
|
53
25
|
if reflex
|
54
|
-
reflex.rescue_with_handler(
|
55
|
-
|
26
|
+
reflex.rescue_with_handler(exception)
|
27
|
+
puts error_message
|
28
|
+
reflex.broadcast_message subject: "error", data: data, error: exception
|
56
29
|
else
|
57
|
-
puts
|
30
|
+
puts error_message
|
58
31
|
|
59
32
|
if body.to_s.include? "No route matches"
|
60
33
|
initializer_path = Rails.root.join("config", "initializers", "stimulus_reflex.rb")
|
@@ -84,64 +57,60 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
|
|
84
57
|
reflex.broadcast_message subject: "halted", data: data
|
85
58
|
else
|
86
59
|
begin
|
87
|
-
reflex.broadcast(selectors, data)
|
88
|
-
rescue =>
|
89
|
-
reflex.rescue_with_handler(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
puts "\e[31m#{body}\e[0m"
|
60
|
+
reflex.broadcast(reflex_data.selectors, data)
|
61
|
+
rescue => exception
|
62
|
+
reflex.rescue_with_handler(exception)
|
63
|
+
error = exception_with_backtrace(exception)
|
64
|
+
reflex.broadcast_message subject: "error", data: data, error: exception
|
65
|
+
puts "\e[31mReflex failed to re-render: #{error[:message]} [#{reflex_data.url}]\e[0m\n#{error[:stack]}"
|
94
66
|
end
|
95
67
|
end
|
96
68
|
ensure
|
97
69
|
if reflex
|
98
70
|
commit_session(reflex)
|
99
|
-
reflex.
|
71
|
+
report_failed_basic_auth(reflex) if reflex.controller?
|
72
|
+
reflex.logger&.print
|
100
73
|
end
|
101
74
|
end
|
102
75
|
end
|
103
76
|
|
104
77
|
private
|
105
78
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
109
|
-
object
|
110
|
-
end
|
111
|
-
|
112
|
-
def is_reflex?(reflex_class)
|
113
|
-
reflex_class.ancestors.include? StimulusReflex::Reflex
|
114
|
-
end
|
115
|
-
|
116
|
-
def delegate_call_to_reflex(reflex, method_name, arguments = [])
|
79
|
+
def delegate_call_to_reflex(reflex)
|
80
|
+
method_name = reflex_data.method_name
|
81
|
+
arguments = reflex_data.arguments
|
117
82
|
method = reflex.method(method_name)
|
118
|
-
required_params = method.parameters.select { |(kind, _)| kind == :req }
|
119
|
-
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
120
83
|
|
121
|
-
|
84
|
+
policy = StimulusReflex::ReflexMethodInvocationPolicy.new(method, arguments)
|
85
|
+
|
86
|
+
if policy.no_arguments?
|
122
87
|
reflex.process(method_name)
|
123
|
-
elsif
|
88
|
+
elsif policy.arguments?
|
124
89
|
reflex.process(method_name, *arguments)
|
125
90
|
else
|
126
|
-
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
|
91
|
+
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{policy.required_params.inspect}, optional #{policy.optional_params.inspect})")
|
127
92
|
end
|
128
93
|
end
|
129
94
|
|
130
95
|
def commit_session(reflex)
|
131
96
|
store = reflex.request.session.instance_variable_get("@by")
|
132
97
|
store.commit_session reflex.request, reflex.controller.response
|
133
|
-
rescue =>
|
134
|
-
|
135
|
-
puts "\e[
|
98
|
+
rescue => exception
|
99
|
+
error = exception_with_backtrace(exception)
|
100
|
+
puts "\e[31mFailed to commit session! #{error[:message]}\e[0m\n#{error[:backtrace]}"
|
136
101
|
end
|
137
102
|
|
138
|
-
def
|
139
|
-
|
103
|
+
def report_failed_basic_auth(reflex)
|
104
|
+
if reflex.controller.response.status == 401
|
105
|
+
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"
|
106
|
+
end
|
140
107
|
end
|
141
108
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
109
|
+
def exception_with_backtrace(exception)
|
110
|
+
{
|
111
|
+
message: exception.to_s,
|
112
|
+
backtrace: exception.backtrace.first,
|
113
|
+
stack: exception.backtrace.join("\n")
|
114
|
+
}
|
146
115
|
end
|
147
116
|
end
|