stimulus_reflex 3.2.1 → 3.2.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -1
- data/Gemfile.lock +58 -60
- data/README.md +1 -1
- data/lib/generators/templates/custom_reflex.rb +1 -0
- data/lib/stimulus_reflex/channel.rb +33 -16
- data/lib/stimulus_reflex/element.rb +9 -10
- data/lib/stimulus_reflex/reflex.rb +7 -1
- data/lib/stimulus_reflex/version.rb +1 -1
- data/stimulus_reflex.gemspec +1 -1
- data/test/tmp/app/reflexes/demo_reflex.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd9af85e63dfa792a38d7dd4a560f86c1bcca6898aa8f38882ccfea57e726dbd
|
|
4
|
+
data.tar.gz: d4fdcadaae536283af5db9e98551a5dbd1cd9aa3100bba806be82e5cf6aecd18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a64205414cfc3630ecb2c537abe5f0deacd0737f5abcf9d33873d57b317d5bf0dfccee6ae09706fdf1e38a5ca7ea6d3159272abd4a293523f9451600ce8d43f7
|
|
7
|
+
data.tar.gz: 81792f053d071fe1fc63db27609a53b4147b9d0f02f85714ba8c81f7cf7e937f94aca5037845badcdbb7b24e78992152549a991a3a1db5a1e1563d9b1f574713
|
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased](https://github.com/hopsoft/stimulus_reflex/tree/HEAD)
|
|
4
4
|
|
|
5
|
-
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.
|
|
5
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.1...HEAD)
|
|
6
|
+
|
|
7
|
+
**Implemented enhancements:**
|
|
8
|
+
|
|
9
|
+
- Add a halted lifecycle event [\#190](https://github.com/hopsoft/stimulus_reflex/issues/190)
|
|
10
|
+
- Allow extractElementAttributes to use a checkbox list [\#147](https://github.com/hopsoft/stimulus_reflex/issues/147)
|
|
11
|
+
- reflex\_name restriction loosening [\#212](https://github.com/hopsoft/stimulus_reflex/pull/212) ([leastbad](https://github.com/leastbad))
|
|
12
|
+
- Make element even more user friendly [\#210](https://github.com/hopsoft/stimulus_reflex/pull/210) ([hopsoft](https://github.com/hopsoft))
|
|
13
|
+
- Form parameters [\#204](https://github.com/hopsoft/stimulus_reflex/pull/204) ([jasoncharnes](https://github.com/jasoncharnes))
|
|
14
|
+
- Map hashes in incoming arguments using with\_indifferent\_access [\#203](https://github.com/hopsoft/stimulus_reflex/pull/203) ([jaredcwhite](https://github.com/jaredcwhite))
|
|
15
|
+
- Combine dataset with data-attributes from parent elements on reflex call [\#200](https://github.com/hopsoft/stimulus_reflex/pull/200) ([marcoroth](https://github.com/marcoroth))
|
|
16
|
+
- Setup mutation aware declarative reflexes [\#197](https://github.com/hopsoft/stimulus_reflex/pull/197) ([hopsoft](https://github.com/hopsoft))
|
|
17
|
+
|
|
18
|
+
**Fixed bugs:**
|
|
19
|
+
|
|
20
|
+
- Text area values are lost if re-sized [\#195](https://github.com/hopsoft/stimulus_reflex/issues/195)
|
|
21
|
+
|
|
22
|
+
**Closed issues:**
|
|
23
|
+
|
|
24
|
+
- Accessing dataset as before is returning nil [\#218](https://github.com/hopsoft/stimulus_reflex/issues/218)
|
|
25
|
+
- Spurious console error using data-reflex-root and CSS attribute selector [\#207](https://github.com/hopsoft/stimulus_reflex/issues/207)
|
|
26
|
+
- ActionController Parameters [\#199](https://github.com/hopsoft/stimulus_reflex/issues/199)
|
|
27
|
+
|
|
28
|
+
**Merged pull requests:**
|
|
29
|
+
|
|
30
|
+
- Bump activesupport from 6.0.3 to 6.0.3.1 [\#217](https://github.com/hopsoft/stimulus_reflex/pull/217) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
31
|
+
- Bump activestorage from 6.0.3 to 6.0.3.1 [\#216](https://github.com/hopsoft/stimulus_reflex/pull/216) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
32
|
+
- Bump actionpack from 6.0.3 to 6.0.3.1 [\#215](https://github.com/hopsoft/stimulus_reflex/pull/215) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
33
|
+
- Update dataset handling and some minor refactoring to better naming [\#214](https://github.com/hopsoft/stimulus_reflex/pull/214) ([hopsoft](https://github.com/hopsoft))
|
|
34
|
+
- Stimulus reflexData assignment after callback [\#208](https://github.com/hopsoft/stimulus_reflex/pull/208) ([jasoncharnes](https://github.com/jasoncharnes))
|
|
35
|
+
- Loosen Rails requirement to 5.2 with instructions [\#205](https://github.com/hopsoft/stimulus_reflex/pull/205) ([jasoncharnes](https://github.com/jasoncharnes))
|
|
36
|
+
- Fix undefined is not an object for Object.keys in log.js [\#201](https://github.com/hopsoft/stimulus_reflex/pull/201) ([marcoroth](https://github.com/marcoroth))
|
|
37
|
+
- Small typo/grammar fix in quickstart doc. [\#198](https://github.com/hopsoft/stimulus_reflex/pull/198) ([acoffman](https://github.com/acoffman))
|
|
38
|
+
- Add halted lifecycle event [\#193](https://github.com/hopsoft/stimulus_reflex/pull/193) ([seb1441](https://github.com/seb1441))
|
|
39
|
+
- 147 extract multiple checkbox values [\#175](https://github.com/hopsoft/stimulus_reflex/pull/175) ([julianrubisch](https://github.com/julianrubisch))
|
|
40
|
+
|
|
41
|
+
## [v3.2.1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.1) (2020-05-09)
|
|
42
|
+
|
|
43
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0...v3.2.1)
|
|
6
44
|
|
|
7
45
|
**Merged pull requests:**
|
|
8
46
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
stimulus_reflex (3.2.
|
|
4
|
+
stimulus_reflex (3.2.2.pre0)
|
|
5
5
|
cable_ready (>= 4.1.2)
|
|
6
6
|
nokogiri
|
|
7
7
|
rack
|
|
8
|
-
rails (>=
|
|
8
|
+
rails (>= 5.2)
|
|
9
9
|
|
|
10
10
|
GEM
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
|
-
actioncable (6.0.3)
|
|
14
|
-
actionpack (= 6.0.3)
|
|
13
|
+
actioncable (6.0.3.1)
|
|
14
|
+
actionpack (= 6.0.3.1)
|
|
15
15
|
nio4r (~> 2.0)
|
|
16
16
|
websocket-driver (>= 0.6.1)
|
|
17
|
-
actionmailbox (6.0.3)
|
|
18
|
-
actionpack (= 6.0.3)
|
|
19
|
-
activejob (= 6.0.3)
|
|
20
|
-
activerecord (= 6.0.3)
|
|
21
|
-
activestorage (= 6.0.3)
|
|
22
|
-
activesupport (= 6.0.3)
|
|
17
|
+
actionmailbox (6.0.3.1)
|
|
18
|
+
actionpack (= 6.0.3.1)
|
|
19
|
+
activejob (= 6.0.3.1)
|
|
20
|
+
activerecord (= 6.0.3.1)
|
|
21
|
+
activestorage (= 6.0.3.1)
|
|
22
|
+
activesupport (= 6.0.3.1)
|
|
23
23
|
mail (>= 2.7.1)
|
|
24
|
-
actionmailer (6.0.3)
|
|
25
|
-
actionpack (= 6.0.3)
|
|
26
|
-
actionview (= 6.0.3)
|
|
27
|
-
activejob (= 6.0.3)
|
|
24
|
+
actionmailer (6.0.3.1)
|
|
25
|
+
actionpack (= 6.0.3.1)
|
|
26
|
+
actionview (= 6.0.3.1)
|
|
27
|
+
activejob (= 6.0.3.1)
|
|
28
28
|
mail (~> 2.5, >= 2.5.4)
|
|
29
29
|
rails-dom-testing (~> 2.0)
|
|
30
|
-
actionpack (6.0.3)
|
|
31
|
-
actionview (= 6.0.3)
|
|
32
|
-
activesupport (= 6.0.3)
|
|
30
|
+
actionpack (6.0.3.1)
|
|
31
|
+
actionview (= 6.0.3.1)
|
|
32
|
+
activesupport (= 6.0.3.1)
|
|
33
33
|
rack (~> 2.0, >= 2.0.8)
|
|
34
34
|
rack-test (>= 0.6.3)
|
|
35
35
|
rails-dom-testing (~> 2.0)
|
|
36
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
37
|
-
actiontext (6.0.3)
|
|
38
|
-
actionpack (= 6.0.3)
|
|
39
|
-
activerecord (= 6.0.3)
|
|
40
|
-
activestorage (= 6.0.3)
|
|
41
|
-
activesupport (= 6.0.3)
|
|
37
|
+
actiontext (6.0.3.1)
|
|
38
|
+
actionpack (= 6.0.3.1)
|
|
39
|
+
activerecord (= 6.0.3.1)
|
|
40
|
+
activestorage (= 6.0.3.1)
|
|
41
|
+
activesupport (= 6.0.3.1)
|
|
42
42
|
nokogiri (>= 1.8.5)
|
|
43
|
-
actionview (6.0.3)
|
|
44
|
-
activesupport (= 6.0.3)
|
|
43
|
+
actionview (6.0.3.1)
|
|
44
|
+
activesupport (= 6.0.3.1)
|
|
45
45
|
builder (~> 3.1)
|
|
46
46
|
erubi (~> 1.4)
|
|
47
47
|
rails-dom-testing (~> 2.0)
|
|
48
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
49
|
-
activejob (6.0.3)
|
|
50
|
-
activesupport (= 6.0.3)
|
|
49
|
+
activejob (6.0.3.1)
|
|
50
|
+
activesupport (= 6.0.3.1)
|
|
51
51
|
globalid (>= 0.3.6)
|
|
52
|
-
activemodel (6.0.3)
|
|
53
|
-
activesupport (= 6.0.3)
|
|
54
|
-
activerecord (6.0.3)
|
|
55
|
-
activemodel (= 6.0.3)
|
|
56
|
-
activesupport (= 6.0.3)
|
|
57
|
-
activestorage (6.0.3)
|
|
58
|
-
actionpack (= 6.0.3)
|
|
59
|
-
activejob (= 6.0.3)
|
|
60
|
-
activerecord (= 6.0.3)
|
|
52
|
+
activemodel (6.0.3.1)
|
|
53
|
+
activesupport (= 6.0.3.1)
|
|
54
|
+
activerecord (6.0.3.1)
|
|
55
|
+
activemodel (= 6.0.3.1)
|
|
56
|
+
activesupport (= 6.0.3.1)
|
|
57
|
+
activestorage (6.0.3.1)
|
|
58
|
+
actionpack (= 6.0.3.1)
|
|
59
|
+
activejob (= 6.0.3.1)
|
|
60
|
+
activerecord (= 6.0.3.1)
|
|
61
61
|
marcel (~> 0.3.1)
|
|
62
|
-
activesupport (6.0.3)
|
|
62
|
+
activesupport (6.0.3.1)
|
|
63
63
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
64
64
|
i18n (>= 0.7, < 2)
|
|
65
65
|
minitest (~> 5.1)
|
|
@@ -77,7 +77,6 @@ GEM
|
|
|
77
77
|
activesupport (>= 4.2.0)
|
|
78
78
|
i18n (1.8.2)
|
|
79
79
|
concurrent-ruby (~> 1.0)
|
|
80
|
-
jaro_winkler (1.5.4)
|
|
81
80
|
loofah (2.5.0)
|
|
82
81
|
crass (~> 1.0.2)
|
|
83
82
|
nokogiri (>= 1.5.9)
|
|
@@ -89,12 +88,12 @@ GEM
|
|
|
89
88
|
mimemagic (0.3.5)
|
|
90
89
|
mini_mime (1.0.2)
|
|
91
90
|
mini_portile2 (2.4.0)
|
|
92
|
-
minitest (5.14.
|
|
91
|
+
minitest (5.14.1)
|
|
93
92
|
nio4r (2.5.2)
|
|
94
93
|
nokogiri (1.10.9)
|
|
95
94
|
mini_portile2 (~> 2.4.0)
|
|
96
95
|
parallel (1.19.1)
|
|
97
|
-
parser (2.7.1.
|
|
96
|
+
parser (2.7.1.3)
|
|
98
97
|
ast (~> 2.4.0)
|
|
99
98
|
pry (0.12.2)
|
|
100
99
|
coderay (~> 1.1.0)
|
|
@@ -104,37 +103,36 @@ GEM
|
|
|
104
103
|
rack (2.2.2)
|
|
105
104
|
rack-test (1.1.0)
|
|
106
105
|
rack (>= 1.0, < 3)
|
|
107
|
-
rails (6.0.3)
|
|
108
|
-
actioncable (= 6.0.3)
|
|
109
|
-
actionmailbox (= 6.0.3)
|
|
110
|
-
actionmailer (= 6.0.3)
|
|
111
|
-
actionpack (= 6.0.3)
|
|
112
|
-
actiontext (= 6.0.3)
|
|
113
|
-
actionview (= 6.0.3)
|
|
114
|
-
activejob (= 6.0.3)
|
|
115
|
-
activemodel (= 6.0.3)
|
|
116
|
-
activerecord (= 6.0.3)
|
|
117
|
-
activestorage (= 6.0.3)
|
|
118
|
-
activesupport (= 6.0.3)
|
|
106
|
+
rails (6.0.3.1)
|
|
107
|
+
actioncable (= 6.0.3.1)
|
|
108
|
+
actionmailbox (= 6.0.3.1)
|
|
109
|
+
actionmailer (= 6.0.3.1)
|
|
110
|
+
actionpack (= 6.0.3.1)
|
|
111
|
+
actiontext (= 6.0.3.1)
|
|
112
|
+
actionview (= 6.0.3.1)
|
|
113
|
+
activejob (= 6.0.3.1)
|
|
114
|
+
activemodel (= 6.0.3.1)
|
|
115
|
+
activerecord (= 6.0.3.1)
|
|
116
|
+
activestorage (= 6.0.3.1)
|
|
117
|
+
activesupport (= 6.0.3.1)
|
|
119
118
|
bundler (>= 1.3.0)
|
|
120
|
-
railties (= 6.0.3)
|
|
119
|
+
railties (= 6.0.3.1)
|
|
121
120
|
sprockets-rails (>= 2.0.0)
|
|
122
121
|
rails-dom-testing (2.0.3)
|
|
123
122
|
activesupport (>= 4.2.0)
|
|
124
123
|
nokogiri (>= 1.6)
|
|
125
124
|
rails-html-sanitizer (1.3.0)
|
|
126
125
|
loofah (~> 2.3)
|
|
127
|
-
railties (6.0.3)
|
|
128
|
-
actionpack (= 6.0.3)
|
|
129
|
-
activesupport (= 6.0.3)
|
|
126
|
+
railties (6.0.3.1)
|
|
127
|
+
actionpack (= 6.0.3.1)
|
|
128
|
+
activesupport (= 6.0.3.1)
|
|
130
129
|
method_source
|
|
131
130
|
rake (>= 0.8.7)
|
|
132
131
|
thor (>= 0.20.3, < 2.0)
|
|
133
132
|
rainbow (3.0.0)
|
|
134
133
|
rake (13.0.1)
|
|
135
134
|
rexml (3.2.4)
|
|
136
|
-
rubocop (0.
|
|
137
|
-
jaro_winkler (~> 1.5.1)
|
|
135
|
+
rubocop (0.83.0)
|
|
138
136
|
parallel (~> 1.10)
|
|
139
137
|
parser (>= 2.7.0.1)
|
|
140
138
|
rainbow (>= 2.2.2, < 4.0)
|
|
@@ -151,8 +149,8 @@ GEM
|
|
|
151
149
|
actionpack (>= 4.0)
|
|
152
150
|
activesupport (>= 4.0)
|
|
153
151
|
sprockets (>= 3.0.0)
|
|
154
|
-
standard (0.4.
|
|
155
|
-
rubocop (~> 0.
|
|
152
|
+
standard (0.4.6)
|
|
153
|
+
rubocop (~> 0.83.0)
|
|
156
154
|
rubocop-performance (~> 1.5.2)
|
|
157
155
|
standardrb (1.0.0)
|
|
158
156
|
standard
|
|
@@ -161,7 +159,7 @@ GEM
|
|
|
161
159
|
tzinfo (1.2.7)
|
|
162
160
|
thread_safe (~> 0.1)
|
|
163
161
|
unicode-display_width (1.7.0)
|
|
164
|
-
websocket-driver (0.7.
|
|
162
|
+
websocket-driver (0.7.2)
|
|
165
163
|
websocket-extensions (>= 0.1.0)
|
|
166
164
|
websocket-extensions (0.1.4)
|
|
167
165
|
zeitwerk (2.3.0)
|
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-923-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" />
|
|
@@ -11,6 +11,7 @@ class <%= class_name %>Reflex < ApplicationReflex
|
|
|
11
11
|
# - session - the ActionDispatch::Session store for the current visitor
|
|
12
12
|
# - url - the URL of the page that triggered the reflex
|
|
13
13
|
# - element - a Hash like object that represents the HTML element that triggered the reflex
|
|
14
|
+
# - params - parameters from the element's closest form (if any)
|
|
14
15
|
#
|
|
15
16
|
# Example:
|
|
16
17
|
#
|
|
@@ -22,31 +22,42 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
|
|
|
22
22
|
target = data["target"].to_s
|
|
23
23
|
reflex_name, method_name = target.split("#")
|
|
24
24
|
reflex_name = reflex_name.classify
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
params = data["params"] || {}
|
|
27
29
|
|
|
28
30
|
begin
|
|
29
|
-
reflex_class = reflex_name.constantize
|
|
30
|
-
|
|
31
|
-
reflex = reflex_class.new(self, url: url, element: element, selectors: selectors, method_name: method_name)
|
|
31
|
+
reflex_class = reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
|
|
32
|
+
reflex = reflex_class.new(self, url: url, element: element, selectors: selectors, method_name: method_name, params: params)
|
|
32
33
|
delegate_call_to_reflex reflex, method_name, arguments
|
|
33
34
|
rescue => invoke_error
|
|
34
35
|
reflex.rescue_with_handler(invoke_error)
|
|
35
36
|
message = exception_message_with_backtrace(invoke_error)
|
|
36
|
-
return
|
|
37
|
+
return broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data: data
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if reflex.halted?
|
|
41
|
+
broadcast_message subject: "halted", data: data
|
|
42
|
+
else
|
|
43
|
+
begin
|
|
44
|
+
render_page_and_broadcast_morph reflex, selectors, data
|
|
45
|
+
rescue => render_error
|
|
46
|
+
reflex.rescue_with_handler(render_error)
|
|
47
|
+
message = exception_message_with_backtrace(render_error)
|
|
48
|
+
broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to re-render #{url} #{message}", data: data
|
|
49
|
+
end
|
|
45
50
|
end
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
private
|
|
49
54
|
|
|
55
|
+
def object_with_indifferent_access(object)
|
|
56
|
+
return object.with_indifferent_access if object.respond_to?(:with_indifferent_access)
|
|
57
|
+
object.map! { |obj| object_with_indifferent_access obj } if object.is_a?(Array)
|
|
58
|
+
object
|
|
59
|
+
end
|
|
60
|
+
|
|
50
61
|
def is_reflex?(reflex_class)
|
|
51
62
|
reflex_class.ancestors.include? StimulusReflex::Reflex
|
|
52
63
|
end
|
|
@@ -107,11 +118,17 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
|
|
|
107
118
|
cable_ready.broadcast
|
|
108
119
|
end
|
|
109
120
|
|
|
110
|
-
def
|
|
111
|
-
|
|
121
|
+
def broadcast_message(subject:, body: nil, data: {})
|
|
122
|
+
message = {
|
|
123
|
+
subject: subject,
|
|
124
|
+
body: body
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
logger.error "\e[31m#{body}\e[0m" if subject == "error"
|
|
128
|
+
|
|
112
129
|
cable_ready[stream_name].dispatch_event(
|
|
113
|
-
name: "stimulus-reflex:
|
|
114
|
-
detail: {stimulus_reflex: data.merge(
|
|
130
|
+
name: "stimulus-reflex:server-message",
|
|
131
|
+
detail: {stimulus_reflex: data.merge(server_message: message)}
|
|
115
132
|
)
|
|
116
133
|
cable_ready.broadcast
|
|
117
134
|
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
class StimulusReflex::Element
|
|
4
|
-
attr_reader :attributes
|
|
3
|
+
class StimulusReflex::Element < OpenStruct
|
|
4
|
+
attr_reader :attributes, :data_attributes
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
def initialize(data = {})
|
|
7
|
+
@attributes = HashWithIndifferentAccess.new(data["attrs"] || {})
|
|
8
|
+
@data_attributes = HashWithIndifferentAccess.new(data["dataset"] || {})
|
|
9
|
+
all_attributes = @attributes.merge(@data_attributes)
|
|
10
|
+
super all_attributes.merge(all_attributes.transform_keys(&:underscore))
|
|
11
|
+
@data_attributes.transform_keys! { |key| key.delete_prefix "data-" }
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def dataset
|
|
13
|
-
@dataset ||=
|
|
14
|
-
next unless key.start_with?("data-")
|
|
15
|
-
memo[key.delete_prefix("data-")] = value
|
|
16
|
-
}.freeze
|
|
15
|
+
@dataset ||= OpenStruct.new(data_attributes.merge(data_attributes.transform_keys(&:underscore)))
|
|
17
16
|
end
|
|
18
17
|
end
|
|
@@ -47,12 +47,13 @@ class StimulusReflex::Reflex
|
|
|
47
47
|
delegate :connection, to: :channel
|
|
48
48
|
delegate :session, to: :request
|
|
49
49
|
|
|
50
|
-
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil)
|
|
50
|
+
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, params: {})
|
|
51
51
|
@channel = channel
|
|
52
52
|
@url = url
|
|
53
53
|
@element = element
|
|
54
54
|
@selectors = selectors
|
|
55
55
|
@method_name = method_name
|
|
56
|
+
@params = params
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def request
|
|
@@ -76,6 +77,7 @@ class StimulusReflex::Reflex
|
|
|
76
77
|
)
|
|
77
78
|
path_params = Rails.application.routes.recognize_path_with_request(req, url, req.env[:extras] || {})
|
|
78
79
|
req.env.merge(ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params)
|
|
80
|
+
req.env["action_dispatch.request.parameters"] = @params
|
|
79
81
|
req.tap { |r| r.session.send :load! }
|
|
80
82
|
end
|
|
81
83
|
end
|
|
@@ -103,4 +105,8 @@ class StimulusReflex::Reflex
|
|
|
103
105
|
def default_reflex
|
|
104
106
|
# noop default reflex to force page reloads
|
|
105
107
|
end
|
|
108
|
+
|
|
109
|
+
def params
|
|
110
|
+
@_params ||= ActionController::Parameters.new(request.parameters)
|
|
111
|
+
end
|
|
106
112
|
end
|
data/stimulus_reflex.gemspec
CHANGED
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
|
|
|
28
28
|
|
|
29
29
|
gem.add_dependency "rack"
|
|
30
30
|
gem.add_dependency "nokogiri"
|
|
31
|
-
gem.add_dependency "rails", ">=
|
|
31
|
+
gem.add_dependency "rails", ">= 5.2"
|
|
32
32
|
gem.add_dependency "cable_ready", ">= 4.1.2"
|
|
33
33
|
|
|
34
34
|
gem.add_development_dependency "bundler", "~> 2.0"
|
|
@@ -11,6 +11,7 @@ class DemoReflex < ApplicationReflex
|
|
|
11
11
|
# - session - the ActionDispatch::Session store for the current visitor
|
|
12
12
|
# - url - the URL of the page that triggered the reflex
|
|
13
13
|
# - element - a Hash like object that represents the HTML element that triggered the reflex
|
|
14
|
+
# - params - parameters from the element's closest form (if any)
|
|
14
15
|
#
|
|
15
16
|
# Example:
|
|
16
17
|
#
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stimulus_reflex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.2.
|
|
4
|
+
version: 3.2.2.pre0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Hopkins
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-05-
|
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -44,14 +44,14 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '5.2'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '5.2'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: cable_ready
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,9 +197,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
197
197
|
version: '0'
|
|
198
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
requirements:
|
|
200
|
-
- - "
|
|
200
|
+
- - ">"
|
|
201
201
|
- !ruby/object:Gem::Version
|
|
202
|
-
version:
|
|
202
|
+
version: 1.3.1
|
|
203
203
|
requirements: []
|
|
204
204
|
rubygems_version: 3.0.3
|
|
205
205
|
signing_key:
|