stimulus_reflex 3.2.0 → 3.2.3
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 +4 -4
- data/CHANGELOG.md +90 -1
- data/Gemfile.lock +71 -68
- data/README.md +1 -1
- data/lib/generators/templates/custom_reflex.rb +1 -0
- data/lib/stimulus_reflex/channel.rb +48 -36
- data/lib/stimulus_reflex/element.rb +9 -10
- data/lib/stimulus_reflex/reflex.rb +23 -3
- data/lib/stimulus_reflex/version.rb +1 -1
- data/stimulus_reflex.gemspec +1 -1
- data/test/tmp/app/reflexes/posts_reflex.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93021d6229f977ed0e6c37e224b4f066902bce77275c002bd9c94088a936fdde
|
4
|
+
data.tar.gz: d8a1673ffdbd790b003dec9123c4b01458132b645b0164d27e831632680d64b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e69633c961caa4768e60b2e276018031f33383481c8acf4b4e851d8b05743faf39f72e89c562eca7bdef993e07a1987aa7d904a3978441eca0007e902bc7615
|
7
|
+
data.tar.gz: 6147c6ec0f9024d86a2c9ad6d47cc9de90798d68be9f079077197f5ae0b999d38ba8ec913b9d44288ca795aa583e13cd8b1b8a0a53bae302a8cfa513ee73d295
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,94 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [Unreleased](https://github.com/hopsoft/stimulus_reflex/tree/HEAD)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2...HEAD)
|
6
|
+
|
7
|
+
**Fixed bugs:**
|
8
|
+
|
9
|
+
- Add more smarts to \_\_perform [\#235](https://github.com/hopsoft/stimulus_reflex/pull/235) ([hopsoft](https://github.com/hopsoft))
|
10
|
+
- \_\_perform had a bug where it was only ever calling the first event [\#234](https://github.com/hopsoft/stimulus_reflex/pull/234) ([leastbad](https://github.com/leastbad))
|
11
|
+
- merges insteads of overwrites params for reflex actions with form data [\#231](https://github.com/hopsoft/stimulus_reflex/pull/231) ([RolandStuder](https://github.com/RolandStuder))
|
12
|
+
|
13
|
+
**Closed issues:**
|
14
|
+
|
15
|
+
- "Uncaught \(in promise\)" error after failed declarative reflex [\#170](https://github.com/hopsoft/stimulus_reflex/issues/170)
|
16
|
+
|
17
|
+
**Merged pull requests:**
|
18
|
+
|
19
|
+
- Fix typos in the documentation [\#228](https://github.com/hopsoft/stimulus_reflex/pull/228) ([dlt](https://github.com/dlt))
|
20
|
+
|
21
|
+
## [v3.2.2](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2) (2020-06-06)
|
22
|
+
|
23
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2.pre1...v3.2.2)
|
24
|
+
|
25
|
+
**Closed issues:**
|
26
|
+
|
27
|
+
- Issue with doing a partial dom update [\#223](https://github.com/hopsoft/stimulus_reflex/issues/223)
|
28
|
+
|
29
|
+
## [v3.2.2.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2.pre1) (2020-05-30)
|
30
|
+
|
31
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2.pre0...v3.2.2.pre1)
|
32
|
+
|
33
|
+
**Fixed bugs:**
|
34
|
+
|
35
|
+
- Session lost after throw :abort [\#221](https://github.com/hopsoft/stimulus_reflex/issues/221)
|
36
|
+
- Fix multipleInstances convenience method [\#220](https://github.com/hopsoft/stimulus_reflex/pull/220) ([julianrubisch](https://github.com/julianrubisch))
|
37
|
+
|
38
|
+
**Merged pull requests:**
|
39
|
+
|
40
|
+
- Always commit session [\#222](https://github.com/hopsoft/stimulus_reflex/pull/222) ([hopsoft](https://github.com/hopsoft))
|
41
|
+
|
42
|
+
## [v3.2.2.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.2.pre0) (2020-05-27)
|
43
|
+
|
44
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.1...v3.2.2.pre0)
|
45
|
+
|
46
|
+
**Implemented enhancements:**
|
47
|
+
|
48
|
+
- Add a halted lifecycle event [\#190](https://github.com/hopsoft/stimulus_reflex/issues/190)
|
49
|
+
- Allow extractElementAttributes to use a checkbox list [\#147](https://github.com/hopsoft/stimulus_reflex/issues/147)
|
50
|
+
- reflex\_name restriction loosening [\#212](https://github.com/hopsoft/stimulus_reflex/pull/212) ([leastbad](https://github.com/leastbad))
|
51
|
+
- Make element even more user friendly [\#210](https://github.com/hopsoft/stimulus_reflex/pull/210) ([hopsoft](https://github.com/hopsoft))
|
52
|
+
- Form parameters [\#204](https://github.com/hopsoft/stimulus_reflex/pull/204) ([jasoncharnes](https://github.com/jasoncharnes))
|
53
|
+
- Map hashes in incoming arguments using with\_indifferent\_access [\#203](https://github.com/hopsoft/stimulus_reflex/pull/203) ([jaredcwhite](https://github.com/jaredcwhite))
|
54
|
+
- 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))
|
55
|
+
- Setup mutation aware declarative reflexes [\#197](https://github.com/hopsoft/stimulus_reflex/pull/197) ([hopsoft](https://github.com/hopsoft))
|
56
|
+
|
57
|
+
**Fixed bugs:**
|
58
|
+
|
59
|
+
- Text area values are lost if re-sized [\#195](https://github.com/hopsoft/stimulus_reflex/issues/195)
|
60
|
+
|
61
|
+
**Closed issues:**
|
62
|
+
|
63
|
+
- Accessing dataset as before is returning nil [\#218](https://github.com/hopsoft/stimulus_reflex/issues/218)
|
64
|
+
- Spurious console error using data-reflex-root and CSS attribute selector [\#207](https://github.com/hopsoft/stimulus_reflex/issues/207)
|
65
|
+
- ActionController Parameters [\#199](https://github.com/hopsoft/stimulus_reflex/issues/199)
|
66
|
+
|
67
|
+
**Merged pull requests:**
|
68
|
+
|
69
|
+
- 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))
|
70
|
+
- 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))
|
71
|
+
- 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))
|
72
|
+
- Update dataset handling and some minor refactoring to better naming [\#214](https://github.com/hopsoft/stimulus_reflex/pull/214) ([hopsoft](https://github.com/hopsoft))
|
73
|
+
- Stimulus reflexData assignment after callback [\#208](https://github.com/hopsoft/stimulus_reflex/pull/208) ([jasoncharnes](https://github.com/jasoncharnes))
|
74
|
+
- Loosen Rails requirement to 5.2 with instructions [\#205](https://github.com/hopsoft/stimulus_reflex/pull/205) ([jasoncharnes](https://github.com/jasoncharnes))
|
75
|
+
- 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))
|
76
|
+
- Small typo/grammar fix in quickstart doc. [\#198](https://github.com/hopsoft/stimulus_reflex/pull/198) ([acoffman](https://github.com/acoffman))
|
77
|
+
- Add halted lifecycle event [\#193](https://github.com/hopsoft/stimulus_reflex/pull/193) ([seb1441](https://github.com/seb1441))
|
78
|
+
- 147 extract multiple checkbox values [\#175](https://github.com/hopsoft/stimulus_reflex/pull/175) ([julianrubisch](https://github.com/julianrubisch))
|
79
|
+
|
80
|
+
## [v3.2.1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.1) (2020-05-09)
|
81
|
+
|
82
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0...v3.2.1)
|
83
|
+
|
84
|
+
**Merged pull requests:**
|
85
|
+
|
86
|
+
- Prevent halting if reflex returns false [\#194](https://github.com/hopsoft/stimulus_reflex/pull/194) ([hopsoft](https://github.com/hopsoft))
|
87
|
+
|
88
|
+
## [v3.2.0](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0) (2020-05-09)
|
89
|
+
|
90
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0.pre1...v3.2.0)
|
91
|
+
|
3
92
|
## [v3.2.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.2.0.pre1) (2020-05-08)
|
4
93
|
|
5
94
|
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.0-pre0...v3.2.0.pre1)
|
@@ -196,6 +285,7 @@
|
|
196
285
|
**Implemented enhancements:**
|
197
286
|
|
198
287
|
- Explicit and implicit registering of the ActionCable consumer [\#116](https://github.com/hopsoft/stimulus_reflex/pull/116) ([hopsoft](https://github.com/hopsoft))
|
288
|
+
- Add schema support [\#94](https://github.com/hopsoft/stimulus_reflex/pull/94) ([hopsoft](https://github.com/hopsoft))
|
199
289
|
|
200
290
|
## [v2.1.9](https://github.com/hopsoft/stimulus_reflex/tree/v2.1.9) (2020-02-20)
|
201
291
|
|
@@ -250,7 +340,6 @@
|
|
250
340
|
**Implemented enhancements:**
|
251
341
|
|
252
342
|
- Custom Stimulus schema breaks Reflex [\#91](https://github.com/hopsoft/stimulus_reflex/issues/91)
|
253
|
-
- Add schema support [\#94](https://github.com/hopsoft/stimulus_reflex/pull/94) ([hopsoft](https://github.com/hopsoft))
|
254
343
|
- inherit stimulus schema [\#92](https://github.com/hopsoft/stimulus_reflex/pull/92) ([nickyvanurk](https://github.com/nickyvanurk))
|
255
344
|
- Single source of truth [\#76](https://github.com/hopsoft/stimulus_reflex/pull/76) ([leastbad](https://github.com/leastbad))
|
256
345
|
|
data/Gemfile.lock
CHANGED
@@ -1,83 +1,82 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (3.2.
|
4
|
+
stimulus_reflex (3.2.3)
|
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)
|
66
66
|
tzinfo (~> 1.1)
|
67
67
|
zeitwerk (~> 2.2, >= 2.2.2)
|
68
|
-
ast (2.4.
|
68
|
+
ast (2.4.1)
|
69
69
|
builder (3.2.4)
|
70
|
-
cable_ready (4.
|
70
|
+
cable_ready (4.2.0)
|
71
71
|
rails (>= 5.2)
|
72
|
-
coderay (1.1.
|
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.
|
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.
|
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,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.1)
|
135
135
|
rexml (3.2.4)
|
136
|
-
rubocop (0.
|
137
|
-
jaro_winkler (~> 1.5.1)
|
136
|
+
rubocop (0.85.1)
|
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-
|
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.
|
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.
|
155
|
-
rubocop (~> 0.
|
156
|
-
rubocop-performance (~> 1.
|
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.
|
167
|
+
websocket-driver (0.7.2)
|
165
168
|
websocket-extensions (>= 0.1.0)
|
166
|
-
websocket-extensions (0.1.
|
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-
|
14
|
+
<img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-932-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
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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(
|
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
|
83
|
-
controller.
|
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
|
111
|
-
|
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:
|
114
|
-
detail: {stimulus_reflex: data.merge(
|
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
|
-
|
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,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"] = req.parameters.merge(@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
|
-
|
89
|
-
|
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
|
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 PostsReflex < 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.3
|
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-
|
11
|
+
date: 2020-06-15 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
|