stimulus_reflex 3.1.4 → 3.2.2.pre0

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: a559b60e0f9fa9519b36dbdec1a217f15eecbf2a3bff051c20faf91d046c9e89
4
- data.tar.gz: 04af4bf702cd97e692d2f0c0b6396e8c1d86821a53d7352854753b524aa7ba92
3
+ metadata.gz: dd9af85e63dfa792a38d7dd4a560f86c1bcca6898aa8f38882ccfea57e726dbd
4
+ data.tar.gz: d4fdcadaae536283af5db9e98551a5dbd1cd9aa3100bba806be82e5cf6aecd18
5
5
  SHA512:
6
- metadata.gz: 8b5f428fe17bddfeff38c20d400b0b7a25f211b000acd5a0c0578a46379762371ff11f67e81243e20d08fdbeeae585e48c65b2aeb17f7bb6bfc228da7ecd62ce
7
- data.tar.gz: 22df1e093ae82f7454fbd60501622d6d083e69e5c00732dbf953221b9a113d901aa7d347ee82b19a74b9bed75e918c60749bc71caf0f8e9f038619e0464dcf6d
6
+ metadata.gz: a64205414cfc3630ecb2c537abe5f0deacd0737f5abcf9d33873d57b317d5bf0dfccee6ae09706fdf1e38a5ca7ea6d3159272abd4a293523f9451600ce8d43f7
7
+ data.tar.gz: 81792f053d071fe1fc63db27609a53b4147b9d0f02f85714ba8c81f7cf7e937f94aca5037845badcdbb7b24e78992152549a991a3a1db5a1e1563d9b1f574713
@@ -2,7 +2,98 @@
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.3...HEAD)
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)
44
+
45
+ **Merged pull requests:**
46
+
47
+ - Prevent halting if reflex returns false [\#194](https://github.com/hopsoft/stimulus_reflex/pull/194) ([hopsoft](https://github.com/hopsoft))
48
+
49
+ ## [v3.2.0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0) (2020-05-09)
50
+
51
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre1...v3.2.0)
52
+
53
+ ## [v3.2.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre1) (2020-05-08)
54
+
55
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0-pre0...v3.2.0.pre1)
56
+
57
+ **Fixed bugs:**
58
+
59
+ - Add guard to morph that checks stimulusReflex [\#191](https://github.com/hopsoft/stimulus_reflex/pull/191) ([hopsoft](https://github.com/hopsoft))
60
+
61
+ ## [v3.2.0-pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0-pre0) (2020-05-07)
62
+
63
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre0...v3.2.0-pre0)
64
+
65
+ ## [v3.2.0.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre0) (2020-05-07)
66
+
67
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.1.4...v3.2.0.pre0)
68
+
69
+ **Implemented enhancements:**
70
+
71
+ - Stimulate without a reflex target [\#179](https://github.com/hopsoft/stimulus_reflex/issues/179)
72
+ - Reflex callbacks [\#155](https://github.com/hopsoft/stimulus_reflex/issues/155)
73
+ - Replace camelize with homegrown version [\#184](https://github.com/hopsoft/stimulus_reflex/pull/184) ([jonathan-s](https://github.com/jonathan-s))
74
+ - Replace uuid4 dependency with function in repo [\#181](https://github.com/hopsoft/stimulus_reflex/pull/181) ([jonathan-s](https://github.com/jonathan-s))
75
+ - Allow channel exceptions to be rescuable [\#180](https://github.com/hopsoft/stimulus_reflex/pull/180) ([dark-panda](https://github.com/dark-panda))
76
+ - add console log messages for every reflex call [\#163](https://github.com/hopsoft/stimulus_reflex/pull/163) ([marcoroth](https://github.com/marcoroth))
77
+ - add reflex callbacks [\#160](https://github.com/hopsoft/stimulus_reflex/pull/160) ([seb1441](https://github.com/seb1441))
78
+
79
+ **Fixed bugs:**
80
+
81
+ - 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))
82
+
83
+ **Closed issues:**
84
+
85
+ - The ActionCable connection is not open! `this.isActionCableConnectionOpen\(\)` must return true before calling `this.stimulate\(\)` [\#187](https://github.com/hopsoft/stimulus_reflex/issues/187)
86
+ - Promises just resolve with last Partial DOM update [\#171](https://github.com/hopsoft/stimulus_reflex/issues/171)
87
+
88
+ **Merged pull requests:**
89
+
90
+ - Some housekeeping [\#189](https://github.com/hopsoft/stimulus_reflex/pull/189) ([hopsoft](https://github.com/hopsoft))
91
+ - Allow to call stimulate without a reflex target [\#188](https://github.com/hopsoft/stimulus_reflex/pull/188) ([marcoroth](https://github.com/marcoroth))
92
+ - Fix bug in super documentation [\#174](https://github.com/hopsoft/stimulus_reflex/pull/174) ([silva96](https://github.com/silva96))
93
+
94
+ ## [v3.1.4](https://github.com/hopsoft/stimulus_reflex/tree/v3.1.4) (2020-04-27)
95
+
96
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.1.3...v3.1.4)
6
97
 
7
98
  **Implemented enhancements:**
8
99
 
@@ -1,70 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.1.4)
4
+ stimulus_reflex (3.2.2.pre0)
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)
@@ -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)
@@ -86,15 +85,15 @@ GEM
86
85
  marcel (0.3.3)
87
86
  mimemagic (~> 0.3.2)
88
87
  method_source (0.9.2)
89
- mimemagic (0.3.4)
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.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,43 +103,42 @@ 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.80.1)
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)
141
139
  rexml
142
140
  ruby-progressbar (~> 1.7)
143
- unicode-display_width (>= 1.4.0, < 1.7)
141
+ unicode-display_width (>= 1.4.0, < 2.0)
144
142
  rubocop-performance (1.5.2)
145
143
  rubocop (>= 0.71.0)
146
144
  ruby-progressbar (1.10.1)
@@ -151,8 +149,8 @@ GEM
151
149
  actionpack (>= 4.0)
152
150
  activesupport (>= 4.0)
153
151
  sprockets (>= 3.0.0)
154
- standard (0.2.4)
155
- rubocop (~> 0.80.1)
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
@@ -160,8 +158,8 @@ GEM
160
158
  thread_safe (0.3.6)
161
159
  tzinfo (1.2.7)
162
160
  thread_safe (~> 0.1)
163
- unicode-display_width (1.6.1)
164
- websocket-driver (0.7.1)
161
+ unicode-display_width (1.7.0)
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-684-brightgreen.svg?style=flat" />
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" />
@@ -68,6 +68,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
68
68
 
69
69
  ## ✨ Demos
70
70
 
71
+ - https://youtu.be/F5hA79vKE_E
71
72
  - http://expo.stimulusreflex.com
72
73
 
73
74
  ## 💙 Community
@@ -5,6 +5,10 @@ require "rails/generators"
5
5
  class StimulusReflexGenerator < Rails::Generators::NamedBase
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
+ def initialize_application_reflexes
9
+ copy_application_files if behavior == :invoke
10
+ end
11
+
8
12
  def initialize_reflexes
9
13
  copy_reflex_files
10
14
  end
@@ -19,12 +23,15 @@ class StimulusReflexGenerator < Rails::Generators::NamedBase
19
23
  REFLEX_BASE_PATH = "app/reflexes"
20
24
 
21
25
  def copy_reflex_files
22
- template "application_reflex.rb", File.join(REFLEX_BASE_PATH, "application_reflex.rb")
23
26
  template "custom_reflex.rb", File.join(REFLEX_BASE_PATH, "#{name.underscore}_reflex.rb")
24
27
  end
25
28
 
26
29
  def copy_controller_files
27
- template "application_controller.js", File.join(CONTROLLER_BASE_PATH, "application_controller.js")
28
30
  template "custom_controller.js", File.join(CONTROLLER_BASE_PATH, "#{name.underscore}_controller.js")
29
31
  end
32
+
33
+ def copy_application_files
34
+ template "application_reflex.rb", File.join(REFLEX_BASE_PATH, "application_reflex.rb")
35
+ template "application_controller.js", File.join(CONTROLLER_BASE_PATH, "application_controller.js")
36
+ end
30
37
  end
@@ -1,6 +1,6 @@
1
1
  import ApplicationController from './application_controller'
2
2
 
3
- /* This is the custom StimulusReflex controller for <%= @name.classify %>Reflex.
3
+ /* This is the custom StimulusReflex controller for <%= class_name %>Reflex.
4
4
  * Learn more at: https://docs.stimulusreflex.com
5
5
  */
6
6
  export default class extends ApplicationController {
@@ -10,14 +10,14 @@ export default class extends ApplicationController {
10
10
  *
11
11
  * Example:
12
12
  *
13
- * <a href="#" data-reflex="<%= @name.classify %>Reflex#example">Example</a>
13
+ * <a href="#" data-reflex="<%= class_name %>Reflex#example">Example</a>
14
14
  *
15
15
  * Arguments:
16
16
  *
17
17
  * element - the element that triggered the reflex
18
18
  * may be different than the Stimulus controller's this.element
19
19
  *
20
- * reflex - the name of the reflex e.g. "<%= @name.classify %>Reflex#example"
20
+ * reflex - the name of the reflex e.g. "<%= class_name %>Reflex#example"
21
21
  *
22
22
  * error - error message from the server
23
23
  */
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class <%= @name.classify %>Reflex < ApplicationReflex
3
+ class <%= class_name %>Reflex < ApplicationReflex
4
4
  # Add Reflex methods in this file.
5
5
  #
6
6
  # All Reflex instances expose the following properties:
@@ -11,6 +11,7 @@ class <%= @name.classify %>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,29 +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
- 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)
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
35
+ reflex.rescue_with_handler(invoke_error)
34
36
  message = exception_message_with_backtrace(invoke_error)
35
- return broadcast_error("StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data)
37
+ return broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data: data
36
38
  end
37
39
 
38
- begin
39
- render_page_and_broadcast_morph reflex, selectors, data
40
- rescue => render_error
41
- message = exception_message_with_backtrace(render_error)
42
- broadcast_error "StimulusReflex::Channel Failed to re-render #{url} #{message}", data
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
43
50
  end
44
51
  end
45
52
 
46
53
  private
47
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
+
48
61
  def is_reflex?(reflex_class)
49
62
  reflex_class.ancestors.include? StimulusReflex::Reflex
50
63
  end
@@ -55,9 +68,9 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
55
68
  optional_params = method.parameters.select { |(kind, _)| kind == :opt }
56
69
 
57
70
  if arguments.size == 0 && required_params.size == 0
58
- reflex.public_send method_name
71
+ reflex.process(method_name)
59
72
  elsif arguments.size >= required_params.size && arguments.size <= required_params.size + optional_params.size
60
- reflex.public_send method_name, *arguments
73
+ reflex.process(method_name, *arguments)
61
74
  else
62
75
  raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
63
76
  end
@@ -105,11 +118,17 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
105
118
  cable_ready.broadcast
106
119
  end
107
120
 
108
- def broadcast_error(message, data = {})
109
- logger.error "\e[31m#{message}\e[0m"
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
+
110
129
  cable_ready[stream_name].dispatch_event(
111
- name: "stimulus-reflex:500",
112
- detail: {stimulus_reflex: data.merge(error: message)}
130
+ name: "stimulus-reflex:server-message",
131
+ detail: {stimulus_reflex: data.merge(server_message: message)}
113
132
  )
114
133
  cable_ready.broadcast
115
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
- 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
@@ -1,16 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StimulusReflex::Reflex
4
- attr_reader :channel, :url, :element, :selectors
4
+ include ActiveSupport::Rescuable
5
+ include ActiveSupport::Callbacks
6
+
7
+ define_callbacks :process, skip_after_callbacks_if_terminated: true
8
+
9
+ class << self
10
+ def before_reflex(*args, &block)
11
+ add_callback(:before, *args, &block)
12
+ end
13
+
14
+ def after_reflex(*args, &block)
15
+ add_callback(:after, *args, &block)
16
+ end
17
+
18
+ def around_reflex(*args, &block)
19
+ add_callback(:around, *args, &block)
20
+ end
21
+
22
+ private
23
+
24
+ def add_callback(kind, *args, &block)
25
+ options = args.extract_options!
26
+ options.assert_valid_keys :if, :unless, :only, :except
27
+ set_callback(*[:process, kind, args, normalize_callback_options!(options)].flatten, &block)
28
+ end
29
+
30
+ def normalize_callback_options!(options)
31
+ normalize_callback_option! options, :only, :if
32
+ normalize_callback_option! options, :except, :unless
33
+ options
34
+ end
35
+
36
+ def normalize_callback_option!(options, from, to)
37
+ if (from = options.delete(from))
38
+ from_set = Array(from).map(&:to_s).to_set
39
+ from = proc { |reflex| from_set.include? reflex.method_name }
40
+ options[to] = Array(options[to]).unshift(from)
41
+ end
42
+ end
43
+ end
44
+
45
+ attr_reader :channel, :url, :element, :selectors, :method_name
5
46
 
6
47
  delegate :connection, to: :channel
7
48
  delegate :session, to: :request
8
49
 
9
- def initialize(channel, url: nil, element: nil, selectors: [])
50
+ def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, params: {})
10
51
  @channel = channel
11
52
  @url = url
12
53
  @element = element
13
54
  @selectors = selectors
55
+ @method_name = method_name
56
+ @params = params
14
57
  end
15
58
 
16
59
  def request
@@ -34,6 +77,7 @@ class StimulusReflex::Reflex
34
77
  )
35
78
  path_params = Rails.application.routes.recognize_path_with_request(req, url, req.env[:extras] || {})
36
79
  req.env.merge(ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params)
80
+ req.env["action_dispatch.request.parameters"] = @params
37
81
  req.tap { |r| r.session.send :load! }
38
82
  end
39
83
  end
@@ -41,4 +85,28 @@ class StimulusReflex::Reflex
41
85
  def url_params
42
86
  @url_params ||= Rails.application.routes.recognize_path_with_request(request, request.path, request.env[:extras] || {})
43
87
  end
88
+
89
+ def process(name, *args)
90
+ reflex_invoked = false
91
+ result = run_callbacks(:process) {
92
+ public_send(name, *args).tap { reflex_invoked = true }
93
+ }
94
+ @halted ||= result == false && !reflex_invoked
95
+ result
96
+ end
97
+
98
+ # Indicates if the callback chain was halted via a throw(:abort) in a before_reflex callback.
99
+ # SEE: https://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html
100
+ # IMPORTANT: The reflex will not re-render the page if the callback chain is halted
101
+ def halted?
102
+ !!@halted
103
+ end
104
+
105
+ def default_reflex
106
+ # noop default reflex to force page reloads
107
+ end
108
+
109
+ def params
110
+ @_params ||= ActionController::Parameters.new(request.parameters)
111
+ end
44
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "3.1.4"
4
+ VERSION = "3.2.2.pre0"
5
5
  end
@@ -18,13 +18,24 @@ namespace :stimulus_reflex do
18
18
  end
19
19
  puts "Updating #{filepath}"
20
20
  lines = File.open(filepath, "r") { |f| f.readlines }
21
- import_line = lines.find { |line| line.start_with?("import StimulusReflex") }
22
- initialize_line = lines.find { |line| line.start_with?("StimulusReflex.initialize") }
23
- unless import_line
21
+
22
+ unless lines.find { |line| line.start_with?("import StimulusReflex") }
24
23
  matches = lines.select { |line| line =~ /\A(require|import)/ }
25
24
  lines.insert lines.index(matches.last).to_i + 1, "import StimulusReflex from 'stimulus_reflex'\n"
26
25
  end
27
- lines << "StimulusReflex.initialize(application)\n" unless initialize_line
26
+
27
+ unless lines.find { |line| line.start_with?("import consumer") }
28
+ matches = lines.select { |line| line =~ /\A(require|import)/ }
29
+ lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
30
+ end
31
+
32
+ unless lines.find { |line| line.start_with?("import controller") }
33
+ matches = lines.select { |line| line =~ /\A(require|import)/ }
34
+ lines.insert lines.index(matches.last).to_i + 1, "import controller from './application_controller'\n"
35
+ end
36
+
37
+ initialize_line = lines.find { |line| line.start_with?("StimulusReflex.initialize") }
38
+ lines << "StimulusReflex.initialize(application, { consumer, controller, debug: false })\n" unless initialize_line
28
39
  File.open(filepath, "w") { |f| f.write lines.join }
29
40
 
30
41
  filepath = Rails.root.join("config/environments/development.rb")
@@ -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"
@@ -8,11 +8,19 @@ class StimulusReflexGeneratorTest < Rails::Generators::TestCase
8
8
  destination File.expand_path("../../tmp", __FILE__)
9
9
  setup :prepare_destination
10
10
 
11
- test "creates named controller and reflex files" do
11
+ test "creates singular named controller and reflex files" do
12
12
  run_generator %w[demo]
13
13
  assert_file "app/javascript/controllers/application_controller.js"
14
14
  assert_file "app/javascript/controllers/demo_controller.js", /DemoReflex/
15
15
  assert_file "app/reflexes/application_reflex.rb"
16
16
  assert_file "app/reflexes/demo_reflex.rb", /DemoReflex/
17
17
  end
18
+
19
+ test "creates plural named controller and reflex files" do
20
+ run_generator %w[posts]
21
+ assert_file "app/javascript/controllers/application_controller.js"
22
+ assert_file "app/javascript/controllers/posts_controller.js", /PostsReflex/
23
+ assert_file "app/reflexes/application_reflex.rb"
24
+ assert_file "app/reflexes/posts_reflex.rb", /PostsReflex/
25
+ end
18
26
  end
@@ -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.1.4
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-04-27 00:00:00.000000000 Z
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: '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,11 +197,11 @@ 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: '0'
202
+ version: 1.3.1
203
203
  requirements: []
204
- rubygems_version: 3.1.2
204
+ rubygems_version: 3.0.3
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Build reactive applications with the Rails tooling you already know and love.