stimulus_reflex 3.2.0.pre0 → 3.2.2.pre1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea3e0dabfb3b7b82b035f2b63db76ea575452a465e07bd992dd3d7a270e89dab
4
- data.tar.gz: 1f26c53eaa26520dd2697c50996b690f6116476eb6235bf126c2fc31991b677c
3
+ metadata.gz: 942a479c551dc9a4cbcb6b70e4b51b5bf1ae947ad8b5fd159f69bdb92c580349
4
+ data.tar.gz: 7e0eda3f0e7f50f132f8bcfa2528df67502afba73348393b795ed99e15ce6031
5
5
  SHA512:
6
- metadata.gz: ac488c852fa0af0083522553addc0423b99914981719ef988f03101ded5a7be2dfe448959ac0640a5082a0e40f12e303788ddde0fcd4086a4dcd831ba408a6d7
7
- data.tar.gz: 8c80b5cae19be15c6dd3519565872b92de7729b19a7a768eebcfe342ebe66916231a11ddf0bed224da574f7ea4695fad8cf8f4fc98ecfbdc837eb620215ea78f
6
+ metadata.gz: 2df9156de41dda64ff63b1faf2c4a14bd10f9c5fb492018c688438f901a0d16c3646303c1d01484efd7dbaefd7351b4c52ed284e4d4668e2043afe728cd2eb1a
7
+ data.tar.gz: 5afb2906a4b29e8649e77f488e779ec07e47607802a55eceeae56068db96db2a84cd8a12e921d16d01b7f007c380df92f341752779cf436e2ddfed1441154088
@@ -2,7 +2,82 @@
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.1.4...HEAD)
5
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2.pre0...HEAD)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Session lost after throw :abort [\#221](https://github.com/hopsoft/stimulus_reflex/issues/221)
10
+ - Fix multipleInstances convenience method [\#220](https://github.com/hopsoft/stimulus_reflex/pull/220) ([julianrubisch](https://github.com/julianrubisch))
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Always commit session [\#222](https://github.com/hopsoft/stimulus_reflex/pull/222) ([hopsoft](https://github.com/hopsoft))
15
+
16
+ ## [v3.2.2.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2.pre0) (2020-05-27)
17
+
18
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.1...v3.2.2.pre0)
19
+
20
+ **Implemented enhancements:**
21
+
22
+ - Add a halted lifecycle event [\#190](https://github.com/hopsoft/stimulus_reflex/issues/190)
23
+ - Allow extractElementAttributes to use a checkbox list [\#147](https://github.com/hopsoft/stimulus_reflex/issues/147)
24
+ - reflex\_name restriction loosening [\#212](https://github.com/hopsoft/stimulus_reflex/pull/212) ([leastbad](https://github.com/leastbad))
25
+ - Make element even more user friendly [\#210](https://github.com/hopsoft/stimulus_reflex/pull/210) ([hopsoft](https://github.com/hopsoft))
26
+ - Form parameters [\#204](https://github.com/hopsoft/stimulus_reflex/pull/204) ([jasoncharnes](https://github.com/jasoncharnes))
27
+ - Map hashes in incoming arguments using with\_indifferent\_access [\#203](https://github.com/hopsoft/stimulus_reflex/pull/203) ([jaredcwhite](https://github.com/jaredcwhite))
28
+ - 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))
29
+ - Setup mutation aware declarative reflexes [\#197](https://github.com/hopsoft/stimulus_reflex/pull/197) ([hopsoft](https://github.com/hopsoft))
30
+
31
+ **Fixed bugs:**
32
+
33
+ - Text area values are lost if re-sized [\#195](https://github.com/hopsoft/stimulus_reflex/issues/195)
34
+
35
+ **Closed issues:**
36
+
37
+ - Accessing dataset as before is returning nil [\#218](https://github.com/hopsoft/stimulus_reflex/issues/218)
38
+ - Spurious console error using data-reflex-root and CSS attribute selector [\#207](https://github.com/hopsoft/stimulus_reflex/issues/207)
39
+ - ActionController Parameters [\#199](https://github.com/hopsoft/stimulus_reflex/issues/199)
40
+
41
+ **Merged pull requests:**
42
+
43
+ - 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))
44
+ - 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))
45
+ - 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))
46
+ - Update dataset handling and some minor refactoring to better naming [\#214](https://github.com/hopsoft/stimulus_reflex/pull/214) ([hopsoft](https://github.com/hopsoft))
47
+ - Stimulus reflexData assignment after callback [\#208](https://github.com/hopsoft/stimulus_reflex/pull/208) ([jasoncharnes](https://github.com/jasoncharnes))
48
+ - Loosen Rails requirement to 5.2 with instructions [\#205](https://github.com/hopsoft/stimulus_reflex/pull/205) ([jasoncharnes](https://github.com/jasoncharnes))
49
+ - 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))
50
+ - Small typo/grammar fix in quickstart doc. [\#198](https://github.com/hopsoft/stimulus_reflex/pull/198) ([acoffman](https://github.com/acoffman))
51
+ - Add halted lifecycle event [\#193](https://github.com/hopsoft/stimulus_reflex/pull/193) ([seb1441](https://github.com/seb1441))
52
+ - 147 extract multiple checkbox values [\#175](https://github.com/hopsoft/stimulus_reflex/pull/175) ([julianrubisch](https://github.com/julianrubisch))
53
+
54
+ ## [v3.2.1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.1) (2020-05-09)
55
+
56
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0...v3.2.1)
57
+
58
+ **Merged pull requests:**
59
+
60
+ - Prevent halting if reflex returns false [\#194](https://github.com/hopsoft/stimulus_reflex/pull/194) ([hopsoft](https://github.com/hopsoft))
61
+
62
+ ## [v3.2.0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0) (2020-05-09)
63
+
64
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre1...v3.2.0)
65
+
66
+ ## [v3.2.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre1) (2020-05-08)
67
+
68
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0-pre0...v3.2.0.pre1)
69
+
70
+ **Fixed bugs:**
71
+
72
+ - Add guard to morph that checks stimulusReflex [\#191](https://github.com/hopsoft/stimulus_reflex/pull/191) ([hopsoft](https://github.com/hopsoft))
73
+
74
+ ## [v3.2.0-pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0-pre0) (2020-05-07)
75
+
76
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre0...v3.2.0-pre0)
77
+
78
+ ## [v3.2.0.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre0) (2020-05-07)
79
+
80
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.1.4...v3.2.0.pre0)
6
81
 
7
82
  **Implemented enhancements:**
8
83
 
@@ -17,7 +92,6 @@
17
92
  **Fixed bugs:**
18
93
 
19
94
  - Pluralize the generated class name, so that will match with the file name [\#178](https://github.com/hopsoft/stimulus_reflex/pull/178) ([darkrubyist](https://github.com/darkrubyist))
20
- - remove changelog rake task [\#150](https://github.com/hopsoft/stimulus_reflex/pull/150) ([andrewmcodes](https://github.com/andrewmcodes))
21
95
 
22
96
  **Closed issues:**
23
97
 
@@ -92,6 +166,7 @@
92
166
  **Fixed bugs:**
93
167
 
94
168
  - Cannot read property 'removeEventListener' of undefined after updating to 3.1.0 [\#151](https://github.com/hopsoft/stimulus_reflex/issues/151)
169
+ - remove changelog rake task [\#150](https://github.com/hopsoft/stimulus_reflex/pull/150) ([andrewmcodes](https://github.com/andrewmcodes))
95
170
 
96
171
  **Closed issues:**
97
172
 
@@ -325,6 +400,7 @@
325
400
 
326
401
  - Add support to configure room via register option [\#52](https://github.com/hopsoft/stimulus_reflex/pull/52) ([hopsoft](https://github.com/hopsoft))
327
402
  - Move gitbook files to docs [\#49](https://github.com/hopsoft/stimulus_reflex/pull/49) ([hopsoft](https://github.com/hopsoft))
403
+ - Allow override of default controller [\#37](https://github.com/hopsoft/stimulus_reflex/pull/37) ([hopsoft](https://github.com/hopsoft))
328
404
 
329
405
  **Closed issues:**
330
406
 
@@ -340,10 +416,10 @@
340
416
  - Updated Minimal Javascript Example in README.md [\#47](https://github.com/hopsoft/stimulus_reflex/pull/47) ([kobaltz](https://github.com/kobaltz))
341
417
  - Setup StimulusReflex controller callbacks [\#45](https://github.com/hopsoft/stimulus_reflex/pull/45) ([hopsoft](https://github.com/hopsoft))
342
418
  - add .vscode directory to .gitignore [\#42](https://github.com/hopsoft/stimulus_reflex/pull/42) ([andrewmcodes](https://github.com/andrewmcodes))
343
- - Allow override of default controller [\#37](https://github.com/hopsoft/stimulus_reflex/pull/37) ([hopsoft](https://github.com/hopsoft))
344
419
  - update the name of the actions per feedback [\#36](https://github.com/hopsoft/stimulus_reflex/pull/36) ([andrewmcodes](https://github.com/andrewmcodes))
345
420
  - update github templates [\#35](https://github.com/hopsoft/stimulus_reflex/pull/35) ([andrewmcodes](https://github.com/andrewmcodes))
346
421
  - Tighten up security of remote invocation [\#32](https://github.com/hopsoft/stimulus_reflex/pull/32) ([hopsoft](https://github.com/hopsoft))
422
+ - Add Ruby magic comment [\#18](https://github.com/hopsoft/stimulus_reflex/pull/18) ([dixpac](https://github.com/dixpac))
347
423
 
348
424
  **Fixed bugs:**
349
425
 
@@ -377,7 +453,6 @@
377
453
  **Implemented enhancements:**
378
454
 
379
455
  - Implicitly send DOM attributes to reflex methods [\#21](https://github.com/hopsoft/stimulus_reflex/pull/21) ([hopsoft](https://github.com/hopsoft))
380
- - Add Ruby magic comment [\#18](https://github.com/hopsoft/stimulus_reflex/pull/18) ([dixpac](https://github.com/dixpac))
381
456
  - Add GitHub Actions for Linters [\#17](https://github.com/hopsoft/stimulus_reflex/pull/17) ([andrewmcodes](https://github.com/andrewmcodes))
382
457
 
383
458
  **Fixed bugs:**
@@ -1,75 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.2.0.pre0)
4
+ stimulus_reflex (3.2.2.pre1)
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.2.2)
14
- actionpack (= 6.0.2.2)
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.2.2)
18
- actionpack (= 6.0.2.2)
19
- activejob (= 6.0.2.2)
20
- activerecord (= 6.0.2.2)
21
- activestorage (= 6.0.2.2)
22
- activesupport (= 6.0.2.2)
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.2.2)
25
- actionpack (= 6.0.2.2)
26
- actionview (= 6.0.2.2)
27
- activejob (= 6.0.2.2)
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.2.2)
31
- actionview (= 6.0.2.2)
32
- activesupport (= 6.0.2.2)
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.2.2)
38
- actionpack (= 6.0.2.2)
39
- activerecord (= 6.0.2.2)
40
- activestorage (= 6.0.2.2)
41
- activesupport (= 6.0.2.2)
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.2.2)
44
- activesupport (= 6.0.2.2)
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.2.2)
50
- activesupport (= 6.0.2.2)
49
+ activejob (6.0.3.1)
50
+ activesupport (= 6.0.3.1)
51
51
  globalid (>= 0.3.6)
52
- activemodel (6.0.2.2)
53
- activesupport (= 6.0.2.2)
54
- activerecord (6.0.2.2)
55
- activemodel (= 6.0.2.2)
56
- activesupport (= 6.0.2.2)
57
- activestorage (6.0.2.2)
58
- actionpack (= 6.0.2.2)
59
- activejob (= 6.0.2.2)
60
- activerecord (= 6.0.2.2)
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.2.2)
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)
66
66
  tzinfo (~> 1.1)
67
- zeitwerk (~> 2.2)
67
+ zeitwerk (~> 2.2, >= 2.2.2)
68
68
  ast (2.4.0)
69
69
  builder (3.2.4)
70
70
  cable_ready (4.1.2)
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)
@@ -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.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,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.2.2)
108
- actioncable (= 6.0.2.2)
109
- actionmailbox (= 6.0.2.2)
110
- actionmailer (= 6.0.2.2)
111
- actionpack (= 6.0.2.2)
112
- actiontext (= 6.0.2.2)
113
- actionview (= 6.0.2.2)
114
- activejob (= 6.0.2.2)
115
- activemodel (= 6.0.2.2)
116
- activerecord (= 6.0.2.2)
117
- activestorage (= 6.0.2.2)
118
- activesupport (= 6.0.2.2)
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.2.2)
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.2.2)
128
- actionpack (= 6.0.2.2)
129
- activesupport (= 6.0.2.2)
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.82.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.3.0)
155
- rubocop (~> 0.82.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.1)
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-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.pre0"
4
+ VERSION = "3.2.2.pre1"
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.pre0
4
+ version: 3.2.2.pre1
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-07 00:00:00.000000000 Z
11
+ date: 2020-05-30 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