stimulus_reflex 3.2.0.pre1 → 3.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef755199c691867f1083ae6b234e155f6945a4a997cd28202985792a4f60549f
4
- data.tar.gz: 26e926810f99fc3ad9574be140cd3b4524a1ce9e3518abac6fdff3a513af4475
3
+ metadata.gz: 937efac65da2fd94f45c4e51711bcb43c043a2c1a7c403ac7e3b7ab3e1418aa8
4
+ data.tar.gz: 1650a98f1ec8134d5acf56deefbb15e8a536457e8bb044b6f002b2e56a7ce4a7
5
5
  SHA512:
6
- metadata.gz: 9f8b7b3b38941887c24252fba67f9627e40b73f6572541ca2ac499b8e0ccb40be1e4993774b4938b15f3f293e1fec675ceaf14cfabc32f05f0f5e86932ceae08
7
- data.tar.gz: e0f0d0362d2a698474b5673036a5c6d3816b0afa814b798fa0e4a54a71a97dd6b622de5f0234a2ce5439d11f203256b8a4dcf976a2a51f9c686631c4817f0783
6
+ metadata.gz: ab6ffdefc511e60dd3b6f2c732d8a11fc8a11ec6d86a3c0887356539859e497c1671d1db18c50361869e8d8072f96f674b8e7ac899dec02a23641c0a3c3535fb
7
+ data.tar.gz: f245124014cfbf5b1d673ea3a5da5781115e0e6d525ff64526e80901651cbcb818df57128ed3ae2121542408079782837835faec67180b657fa2965d702b2f03
@@ -2,7 +2,78 @@
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.0-pre0...HEAD)
5
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2.pre1...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Issue with doing a partial dom update [\#223](https://github.com/hopsoft/stimulus_reflex/issues/223)
10
+
11
+ ## [v3.2.2.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2.pre1) (2020-05-30)
12
+
13
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2.pre0...v3.2.2.pre1)
14
+
15
+ **Fixed bugs:**
16
+
17
+ - Session lost after throw :abort [\#221](https://github.com/hopsoft/stimulus_reflex/issues/221)
18
+ - Fix multipleInstances convenience method [\#220](https://github.com/hopsoft/stimulus_reflex/pull/220) ([julianrubisch](https://github.com/julianrubisch))
19
+
20
+ **Merged pull requests:**
21
+
22
+ - Always commit session [\#222](https://github.com/hopsoft/stimulus_reflex/pull/222) ([hopsoft](https://github.com/hopsoft))
23
+
24
+ ## [v3.2.2.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2.pre0) (2020-05-27)
25
+
26
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.1...v3.2.2.pre0)
27
+
28
+ **Implemented enhancements:**
29
+
30
+ - Add a halted lifecycle event [\#190](https://github.com/hopsoft/stimulus_reflex/issues/190)
31
+ - Allow extractElementAttributes to use a checkbox list [\#147](https://github.com/hopsoft/stimulus_reflex/issues/147)
32
+ - reflex\_name restriction loosening [\#212](https://github.com/hopsoft/stimulus_reflex/pull/212) ([leastbad](https://github.com/leastbad))
33
+ - Make element even more user friendly [\#210](https://github.com/hopsoft/stimulus_reflex/pull/210) ([hopsoft](https://github.com/hopsoft))
34
+ - Form parameters [\#204](https://github.com/hopsoft/stimulus_reflex/pull/204) ([jasoncharnes](https://github.com/jasoncharnes))
35
+ - Map hashes in incoming arguments using with\_indifferent\_access [\#203](https://github.com/hopsoft/stimulus_reflex/pull/203) ([jaredcwhite](https://github.com/jaredcwhite))
36
+ - 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))
37
+ - Setup mutation aware declarative reflexes [\#197](https://github.com/hopsoft/stimulus_reflex/pull/197) ([hopsoft](https://github.com/hopsoft))
38
+
39
+ **Fixed bugs:**
40
+
41
+ - Text area values are lost if re-sized [\#195](https://github.com/hopsoft/stimulus_reflex/issues/195)
42
+
43
+ **Closed issues:**
44
+
45
+ - Accessing dataset as before is returning nil [\#218](https://github.com/hopsoft/stimulus_reflex/issues/218)
46
+ - Spurious console error using data-reflex-root and CSS attribute selector [\#207](https://github.com/hopsoft/stimulus_reflex/issues/207)
47
+ - ActionController Parameters [\#199](https://github.com/hopsoft/stimulus_reflex/issues/199)
48
+
49
+ **Merged pull requests:**
50
+
51
+ - 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))
52
+ - 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))
53
+ - 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))
54
+ - Update dataset handling and some minor refactoring to better naming [\#214](https://github.com/hopsoft/stimulus_reflex/pull/214) ([hopsoft](https://github.com/hopsoft))
55
+ - Stimulus reflexData assignment after callback [\#208](https://github.com/hopsoft/stimulus_reflex/pull/208) ([jasoncharnes](https://github.com/jasoncharnes))
56
+ - Loosen Rails requirement to 5.2 with instructions [\#205](https://github.com/hopsoft/stimulus_reflex/pull/205) ([jasoncharnes](https://github.com/jasoncharnes))
57
+ - 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))
58
+ - Small typo/grammar fix in quickstart doc. [\#198](https://github.com/hopsoft/stimulus_reflex/pull/198) ([acoffman](https://github.com/acoffman))
59
+ - Add halted lifecycle event [\#193](https://github.com/hopsoft/stimulus_reflex/pull/193) ([seb1441](https://github.com/seb1441))
60
+ - 147 extract multiple checkbox values [\#175](https://github.com/hopsoft/stimulus_reflex/pull/175) ([julianrubisch](https://github.com/julianrubisch))
61
+
62
+ ## [v3.2.1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.1) (2020-05-09)
63
+
64
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0...v3.2.1)
65
+
66
+ **Merged pull requests:**
67
+
68
+ - Prevent halting if reflex returns false [\#194](https://github.com/hopsoft/stimulus_reflex/pull/194) ([hopsoft](https://github.com/hopsoft))
69
+
70
+ ## [v3.2.0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0) (2020-05-09)
71
+
72
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre1...v3.2.0)
73
+
74
+ ## [v3.2.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre1) (2020-05-08)
75
+
76
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0-pre0...v3.2.0.pre1)
6
77
 
7
78
  **Fixed bugs:**
8
79
 
@@ -122,6 +193,7 @@
122
193
  - Check the ActionCable connection on stimuluate [\#148](https://github.com/hopsoft/stimulus_reflex/pull/148) ([hopsoft](https://github.com/hopsoft))
123
194
  - Attach element.tagName to extracted attributes [\#146](https://github.com/hopsoft/stimulus_reflex/pull/146) ([julianrubisch](https://github.com/julianrubisch))
124
195
  - Create dynamic changelog [\#143](https://github.com/hopsoft/stimulus_reflex/pull/143) ([andrewmcodes](https://github.com/andrewmcodes))
196
+ - add funding file [\#141](https://github.com/hopsoft/stimulus_reflex/pull/141) ([andrewmcodes](https://github.com/andrewmcodes))
125
197
 
126
198
  **Fixed bugs:**
127
199
 
@@ -149,7 +221,6 @@
149
221
 
150
222
  - update install script to set session store [\#134](https://github.com/hopsoft/stimulus_reflex/pull/134) ([leastbad](https://github.com/leastbad))
151
223
  - update package.json and readme [\#133](https://github.com/hopsoft/stimulus_reflex/pull/133) ([andrewmcodes](https://github.com/andrewmcodes))
152
- - tweak prettier-standard and add actions caching [\#125](https://github.com/hopsoft/stimulus_reflex/pull/125) ([andrewmcodes](https://github.com/andrewmcodes))
153
224
 
154
225
  **Closed issues:**
155
226
 
@@ -161,8 +232,8 @@
161
232
 
162
233
  **Implemented enhancements:**
163
234
 
164
- - add funding file [\#141](https://github.com/hopsoft/stimulus_reflex/pull/141) ([andrewmcodes](https://github.com/andrewmcodes))
165
235
  - Reload session prior to each reflex accessing it [\#131](https://github.com/hopsoft/stimulus_reflex/pull/131) ([hopsoft](https://github.com/hopsoft))
236
+ - tweak prettier-standard and add actions caching [\#125](https://github.com/hopsoft/stimulus_reflex/pull/125) ([andrewmcodes](https://github.com/andrewmcodes))
166
237
 
167
238
  **Closed issues:**
168
239
 
@@ -1,65 +1,65 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.2.0.pre1)
4
+ stimulus_reflex (3.2.2)
5
5
  cable_ready (>= 4.1.2)
6
6
  nokogiri
7
7
  rack
8
- rails (>= 6.0)
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)
@@ -67,17 +67,16 @@ GEM
67
67
  zeitwerk (~> 2.2, >= 2.2.2)
68
68
  ast (2.4.0)
69
69
  builder (3.2.4)
70
- cable_ready (4.1.2)
70
+ cable_ready (4.2.0)
71
71
  rails (>= 5.2)
72
- coderay (1.1.2)
72
+ coderay (1.1.3)
73
73
  concurrent-ruby (1.1.6)
74
74
  crass (1.0.6)
75
75
  erubi (1.9.0)
76
76
  globalid (0.4.2)
77
77
  activesupport (>= 4.2.0)
78
- i18n (1.8.2)
78
+ i18n (1.8.3)
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.0)
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.2)
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,56 +103,60 @@ 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)
134
+ regexp_parser (1.7.0)
135
135
  rexml (3.2.4)
136
- rubocop (0.82.0)
137
- jaro_winkler (~> 1.5.1)
136
+ rubocop (0.85.0)
138
137
  parallel (~> 1.10)
139
138
  parser (>= 2.7.0.1)
140
139
  rainbow (>= 2.2.2, < 4.0)
140
+ regexp_parser (>= 1.7)
141
141
  rexml
142
+ rubocop-ast (>= 0.0.3)
142
143
  ruby-progressbar (~> 1.7)
143
144
  unicode-display_width (>= 1.4.0, < 2.0)
144
- rubocop-performance (1.5.2)
145
+ rubocop-ast (0.0.3)
146
+ parser (>= 2.7.0.1)
147
+ rubocop-performance (1.6.1)
145
148
  rubocop (>= 0.71.0)
146
149
  ruby-progressbar (1.10.1)
147
- sprockets (4.0.0)
150
+ sprockets (4.0.2)
148
151
  concurrent-ruby (~> 1.0)
149
152
  rack (> 1, < 3)
150
153
  sprockets-rails (3.2.1)
151
154
  actionpack (>= 4.0)
152
155
  activesupport (>= 4.0)
153
156
  sprockets (>= 3.0.0)
154
- standard (0.3.0)
155
- rubocop (~> 0.82.0)
156
- rubocop-performance (~> 1.5.2)
157
+ standard (0.4.7)
158
+ rubocop (~> 0.85.0)
159
+ rubocop-performance (~> 1.6.0)
157
160
  standardrb (1.0.0)
158
161
  standard
159
162
  thor (1.0.1)
@@ -161,9 +164,9 @@ GEM
161
164
  tzinfo (1.2.7)
162
165
  thread_safe (~> 0.1)
163
166
  unicode-display_width (1.7.0)
164
- websocket-driver (0.7.1)
167
+ websocket-driver (0.7.2)
165
168
  websocket-extensions (>= 0.1.0)
166
- websocket-extensions (0.1.4)
169
+ websocket-extensions (0.1.5)
167
170
  zeitwerk (2.3.0)
168
171
 
169
172
  PLATFORMS
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
12
12
  </a>
13
13
  <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
14
- <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-805-brightgreen.svg?style=flat" />
14
+ <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-929-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,46 @@ 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
- arguments = data["args"] || []
26
- element = StimulusReflex::Element.new(data["attrs"])
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
- raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(reflex_class)
31
- reflex = reflex_class.new(self, url: url, element: element, selectors: selectors, method_name: method_name)
32
- delegate_call_to_reflex reflex, method_name, arguments
33
- rescue => invoke_error
34
- reflex.rescue_with_handler(invoke_error)
35
- message = exception_message_with_backtrace(invoke_error)
36
- return broadcast_error("StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data)
37
- end
38
-
39
- begin
40
- render_page_and_broadcast_morph reflex, selectors, data unless reflex.halted?
41
- rescue => render_error
42
- reflex.rescue_with_handler(render_error)
43
- message = exception_message_with_backtrace(render_error)
44
- broadcast_error "StimulusReflex::Channel Failed to re-render #{url} #{message}", data
31
+ begin
32
+ reflex_class = reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
33
+ reflex = reflex_class.new(self, url: url, element: element, selectors: selectors, method_name: method_name, params: params)
34
+ delegate_call_to_reflex reflex, method_name, arguments
35
+ rescue => invoke_error
36
+ reflex.rescue_with_handler(invoke_error)
37
+ message = exception_message_with_backtrace(invoke_error)
38
+ return broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data: data
39
+ end
40
+
41
+ if reflex.halted?
42
+ broadcast_message subject: "halted", data: data
43
+ else
44
+ begin
45
+ render_page_and_broadcast_morph reflex, selectors, data
46
+ rescue => render_error
47
+ reflex.rescue_with_handler(render_error)
48
+ message = exception_message_with_backtrace(render_error)
49
+ broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to re-render #{url} #{message}", data: data
50
+ end
51
+ end
52
+ ensure
53
+ commit_session reflex if reflex
45
54
  end
46
55
  end
47
56
 
48
57
  private
49
58
 
59
+ def object_with_indifferent_access(object)
60
+ return object.with_indifferent_access if object.respond_to?(:with_indifferent_access)
61
+ object.map! { |obj| object_with_indifferent_access obj } if object.is_a?(Array)
62
+ object
63
+ end
64
+
50
65
  def is_reflex?(reflex_class)
51
66
  reflex_class.ancestors.include? StimulusReflex::Reflex
52
67
  end
@@ -70,26 +85,17 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
70
85
  broadcast_morphs selectors, data, html if html.present?
71
86
  end
72
87
 
73
- def commit_session(request, response)
74
- store = request.session.instance_variable_get("@by")
75
- store.commit_session request, response
88
+ def commit_session(reflex)
89
+ store = reflex.request.session.instance_variable_get("@by")
90
+ store.commit_session reflex.request, reflex.controller.response
76
91
  rescue => e
77
92
  message = "Failed to commit session! #{exception_message_with_backtrace(e)}"
78
93
  logger.error "\e[31m#{message}\e[0m"
79
94
  end
80
95
 
81
96
  def render_page(reflex)
82
- controller = reflex.request.controller_class.new
83
- controller.instance_variable_set :"@stimulus_reflex", true
84
- reflex.instance_variables.each do |name|
85
- controller.instance_variable_set name, reflex.instance_variable_get(name)
86
- end
87
-
88
- controller.request = reflex.request
89
- controller.response = ActionDispatch::Response.new
90
- controller.process reflex.url_params[:action]
91
- commit_session reflex.request, controller.response
92
- controller.response.body
97
+ reflex.controller.process reflex.url_params[:action]
98
+ reflex.controller.response.body
93
99
  end
94
100
 
95
101
  def broadcast_morphs(selectors, data, html)
@@ -107,11 +113,17 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
107
113
  cable_ready.broadcast
108
114
  end
109
115
 
110
- def broadcast_error(message, data = {})
111
- logger.error "\e[31m#{message}\e[0m"
116
+ def broadcast_message(subject:, body: nil, data: {})
117
+ message = {
118
+ subject: subject,
119
+ body: body
120
+ }
121
+
122
+ logger.error "\e[31m#{body}\e[0m" if subject == "error"
123
+
112
124
  cable_ready[stream_name].dispatch_event(
113
- name: "stimulus-reflex:500",
114
- detail: {stimulus_reflex: data.merge(error: message)}
125
+ name: "stimulus-reflex:server-message",
126
+ detail: {stimulus_reflex: data.merge(server_message: message)}
115
127
  )
116
128
  cable_ready.broadcast
117
129
  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
- delegate :[], to: :"@attributes"
7
-
8
- def initialize(attrs = {})
9
- @attributes = HashWithIndifferentAccess.new(attrs || {}).freeze
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 ||= attributes.each_with_object(HashWithIndifferentAccess.new) { |(key, value), memo|
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,17 +77,32 @@ 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
82
84
 
85
+ def controller
86
+ @controller ||= begin
87
+ request.controller_class.new.tap do |c|
88
+ c.instance_variable_set :"@stimulus_reflex", true
89
+ instance_variables.each { |name| c.instance_variable_set name, instance_variable_get(name) }
90
+ c.request = request
91
+ c.response = ActionDispatch::Response.new
92
+ end
93
+ end
94
+ end
95
+
83
96
  def url_params
84
97
  @url_params ||= Rails.application.routes.recognize_path_with_request(request, request.path, request.env[:extras] || {})
85
98
  end
86
99
 
87
100
  def process(name, *args)
88
- result = run_callbacks(:process) { public_send(name, *args) }
89
- @halted ||= result == false
101
+ reflex_invoked = false
102
+ result = run_callbacks(:process) {
103
+ public_send(name, *args).tap { reflex_invoked = true }
104
+ }
105
+ @halted ||= result == false && !reflex_invoked
90
106
  result
91
107
  end
92
108
 
@@ -100,4 +116,8 @@ class StimulusReflex::Reflex
100
116
  def default_reflex
101
117
  # noop default reflex to force page reloads
102
118
  end
119
+
120
+ def params
121
+ @_params ||= ActionController::Parameters.new(request.parameters)
122
+ end
103
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "3.2.0.pre1"
4
+ VERSION = "3.2.2"
5
5
  end
@@ -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", ">= 6.0"
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.0.pre1
4
+ version: 3.2.2
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-08 00:00:00.000000000 Z
11
+ date: 2020-06-06 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: '6.0'
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: '6.0'
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: 1.3.1
202
+ version: '0'
203
203
  requirements: []
204
204
  rubygems_version: 3.0.3
205
205
  signing_key: