stimulus_reflex 3.4.0.pre3 → 3.4.0.pre8

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -2
  3. data/Gemfile.lock +17 -17
  4. data/README.md +5 -9
  5. data/Rakefile +5 -5
  6. data/app/channels/stimulus_reflex/channel.rb +14 -5
  7. data/bin/console +1 -0
  8. data/bin/standardize +1 -1
  9. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +14 -2
  10. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt +10 -2
  11. data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +19 -9
  12. data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +2 -2
  13. data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +10 -0
  14. data/lib/stimulus_reflex.rb +3 -0
  15. data/lib/stimulus_reflex/broadcasters/broadcaster.rb +11 -6
  16. data/lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb +4 -0
  17. data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +8 -2
  18. data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +12 -2
  19. data/lib/stimulus_reflex/cable_ready_channels.rb +12 -0
  20. data/lib/stimulus_reflex/configuration.rb +4 -1
  21. data/lib/stimulus_reflex/logger.rb +106 -0
  22. data/lib/stimulus_reflex/reflex.rb +14 -10
  23. data/lib/stimulus_reflex/sanity_checker.rb +26 -10
  24. data/lib/stimulus_reflex/utils/colorize.rb +23 -0
  25. data/lib/stimulus_reflex/version.rb +1 -1
  26. data/lib/tasks/stimulus_reflex/install.rake +3 -3
  27. data/package.json +11 -17
  28. data/stimulus_reflex.gemspec +1 -1
  29. data/tags +82 -41
  30. data/test/broadcasters/broadcaster_test.rb +10 -0
  31. data/test/broadcasters/broadcaster_test_case.rb +13 -0
  32. data/test/broadcasters/nothing_broadcaster_test.rb +33 -0
  33. data/test/broadcasters/page_broadcaster_test.rb +73 -0
  34. data/test/broadcasters/selector_broadcaster_test.rb +55 -0
  35. data/test/reflex_test.rb +26 -0
  36. data/test/test_helper.rb +37 -0
  37. data/test/tmp/app/reflexes/application_reflex.rb +2 -2
  38. data/test/tmp/app/reflexes/demo_reflex.rb +34 -0
  39. data/yarn.lock +248 -1793
  40. metadata +30 -15
  41. data/test/tmp/app/reflexes/user_reflex.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 344e0b60c7f18f467821263a5758cc37843cfae000430754ed89d34214363ff3
4
- data.tar.gz: a49f8d18df8d0e2f4d664a70690fd562fd7d4fcc9db3f22d7821f96f67dee03d
3
+ metadata.gz: 2431b50e027a8144cd11458b3de85f9b09bbfac0e3929eee35f3dc62134c742a
4
+ data.tar.gz: e766e76490781882ff539785408ebf48c3f9ef931d09c6322c87900c079ad857
5
5
  SHA512:
6
- metadata.gz: cd85f6455c20f2cad48a8e4c7bda0fe6e46e50fa6bb39d2c67c128a899edd96d815798b913b928ae08c75fb8f55421483249f6acec34e26428a7114fa7e3eb67
7
- data.tar.gz: 3fbb2e6be0b867db5c05997aa0727642e0298d0c13ad14e31c3f811ca4e6b4188db5154ea0c7ada5aeca8a3fb456c6998e35d0f4616e3fa03c636fc710b33056
6
+ metadata.gz: c2168b3fb2da302b53ce7c4010fad3f5fb83e8a129ab83c6dcd45e0638d2c3e8deebdbfdc7dde43197b143c73bee9703b1fe3b3406a73731a887122f28b04d89
7
+ data.tar.gz: ea440d1c4ff00a93ab3574042b793406fd470c9c49205a9d9c3106b2cae78718217aa5e4b70d8024ff5db3a130476ac55a2f8117018bb700203e595164e2277f
@@ -2,7 +2,92 @@
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.4.0.pre2...HEAD)
5
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre7...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - DirectUpload URL not set using morphs [\#396](https://github.com/hopsoft/stimulus_reflex/issues/396)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Delegate render to controller [\#397](https://github.com/hopsoft/stimulus_reflex/pull/397) ([hopsoft](https://github.com/hopsoft))
14
+
15
+ ## [v3.4.0.pre7](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre7) (2020-12-01)
16
+
17
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre6...v3.4.0.pre7)
18
+
19
+ **Closed issues:**
20
+
21
+ - Multiple reflex submissions can lead to unexpected behaviour. [\#391](https://github.com/hopsoft/stimulus_reflex/issues/391)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Trigger piggy back operations after SR operations [\#395](https://github.com/hopsoft/stimulus_reflex/pull/395) ([hopsoft](https://github.com/hopsoft))
26
+ - `invokeLifecycleMethod\(\)`: handle undefined `element` parameter [\#393](https://github.com/hopsoft/stimulus_reflex/pull/393) ([marcoroth](https://github.com/marcoroth))
27
+ - don't warn folks twice [\#392](https://github.com/hopsoft/stimulus_reflex/pull/392) ([leastbad](https://github.com/leastbad))
28
+
29
+ ## [v3.4.0.pre6](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre6) (2020-11-29)
30
+
31
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre5...v3.4.0.pre6)
32
+
33
+ **Merged pull requests:**
34
+
35
+ - Update templates for new stage etc [\#390](https://github.com/hopsoft/stimulus_reflex/pull/390) ([leastbad](https://github.com/leastbad))
36
+ - reflexError and received refactor [\#389](https://github.com/hopsoft/stimulus_reflex/pull/389) ([leastbad](https://github.com/leastbad))
37
+ - add jQuery support to SR library events [\#388](https://github.com/hopsoft/stimulus_reflex/pull/388) ([leastbad](https://github.com/leastbad))
38
+ - dont exit in sanity checker on `stimulus\_reflex:install` [\#387](https://github.com/hopsoft/stimulus_reflex/pull/387) ([marcoroth](https://github.com/marcoroth))
39
+ - Allow `success` and `after` lifecycle methods on replaced elements [\#386](https://github.com/hopsoft/stimulus_reflex/pull/386) ([marcoroth](https://github.com/marcoroth))
40
+ - split SR operations from data.operations [\#385](https://github.com/hopsoft/stimulus_reflex/pull/385) ([leastbad](https://github.com/leastbad))
41
+ - don't show findElement warnings unless debugging [\#384](https://github.com/hopsoft/stimulus_reflex/pull/384) ([leastbad](https://github.com/leastbad))
42
+ - Setup a proxy object that wraps CableReady::Channels [\#382](https://github.com/hopsoft/stimulus_reflex/pull/382) ([hopsoft](https://github.com/hopsoft))
43
+ - non-SR cable\_ready operation pass-through [\#381](https://github.com/hopsoft/stimulus_reflex/pull/381) ([leastbad](https://github.com/leastbad))
44
+
45
+ ## [v3.4.0.pre5](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre5) (2020-11-25)
46
+
47
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre4...v3.4.0.pre5)
48
+
49
+ **Closed issues:**
50
+
51
+ - SR doesn't seem to handle redirects / 302s [\#376](https://github.com/hopsoft/stimulus_reflex/issues/376)
52
+
53
+ **Merged pull requests:**
54
+
55
+ - Move package.json to root of project [\#380](https://github.com/hopsoft/stimulus_reflex/pull/380) ([hopsoft](https://github.com/hopsoft))
56
+ - make element.reflexController a dictionary [\#379](https://github.com/hopsoft/stimulus_reflex/pull/379) ([existentialmutt](https://github.com/existentialmutt))
57
+ - fixed bug preventing callbacks for multiple morphs [\#378](https://github.com/hopsoft/stimulus_reflex/pull/378) ([leastbad](https://github.com/leastbad))
58
+ - Handles to mitigate race conditions when running reflexes in quick succession on the same element [\#377](https://github.com/hopsoft/stimulus_reflex/pull/377) ([existentialmutt](https://github.com/existentialmutt))
59
+ - Exit with nonzero status code [\#375](https://github.com/hopsoft/stimulus_reflex/pull/375) ([julianrubisch](https://github.com/julianrubisch))
60
+
61
+ ## [v3.4.0.pre4](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre4) (2020-11-19)
62
+
63
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre3...v3.4.0.pre4)
64
+
65
+ **Fixed bugs:**
66
+
67
+ - Fix fatal error in `stimulus\_reflex:install` task with Rails 5.2 [\#371](https://github.com/hopsoft/stimulus_reflex/pull/371) ([Matt-Yorkley](https://github.com/Matt-Yorkley))
68
+ - fix nothing morphs and error messages [\#368](https://github.com/hopsoft/stimulus_reflex/pull/368) ([leastbad](https://github.com/leastbad))
69
+
70
+ **Closed issues:**
71
+
72
+ - `stimulus\_reflex:install` fails to complete in Rails 5.2 [\#367](https://github.com/hopsoft/stimulus_reflex/issues/367)
73
+ - Form data still not captured [\#366](https://github.com/hopsoft/stimulus_reflex/issues/366)
74
+ - Console exception when reflex does not update a page that didn't trigger the reflex [\#363](https://github.com/hopsoft/stimulus_reflex/issues/363)
75
+ - Improve server-side logging options [\#264](https://github.com/hopsoft/stimulus_reflex/issues/264)
76
+
77
+ **Merged pull requests:**
78
+
79
+ - use puts instead of ActionCable.logger to sidestep silenced AC logs [\#373](https://github.com/hopsoft/stimulus_reflex/pull/373) ([leastbad](https://github.com/leastbad))
80
+ - Improve logged post\_install.js message [\#372](https://github.com/hopsoft/stimulus_reflex/pull/372) ([forsbergplustwo](https://github.com/forsbergplustwo))
81
+ - Pass additional reflex-related data to reflex from data [\#370](https://github.com/hopsoft/stimulus_reflex/pull/370) ([joshleblanc](https://github.com/joshleblanc))
82
+ - fix: rip out microbundle [\#369](https://github.com/hopsoft/stimulus_reflex/pull/369) ([ParamagicDev](https://github.com/ParamagicDev))
83
+ - Add tests for broadcasters [\#364](https://github.com/hopsoft/stimulus_reflex/pull/364) ([julianrubisch](https://github.com/julianrubisch))
84
+ - Do not run sanity check on `rails generate stimulus\_reflex:config` [\#362](https://github.com/hopsoft/stimulus_reflex/pull/362) ([RolandStuder](https://github.com/RolandStuder))
85
+ - fix: revert CR and @rails/actioncable to dependencies [\#361](https://github.com/hopsoft/stimulus_reflex/pull/361) ([ParamagicDev](https://github.com/ParamagicDev))
86
+ - xpath fix [\#360](https://github.com/hopsoft/stimulus_reflex/pull/360) ([leastbad](https://github.com/leastbad))
87
+
88
+ ## [v3.4.0.pre3](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre3) (2020-11-11)
89
+
90
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre2...v3.4.0.pre3)
6
91
 
7
92
  **Merged pull requests:**
8
93
 
@@ -13,6 +98,7 @@
13
98
  - Add guard clause to return valid empty form data [\#354](https://github.com/hopsoft/stimulus_reflex/pull/354) ([julianrubisch](https://github.com/julianrubisch))
14
99
  - simplify xpath functions [\#353](https://github.com/hopsoft/stimulus_reflex/pull/353) ([leastbad](https://github.com/leastbad))
15
100
  - pass reflex id to reflex [\#352](https://github.com/hopsoft/stimulus_reflex/pull/352) ([joshleblanc](https://github.com/joshleblanc))
101
+ - Fix page morphs inside Rails engines [\#344](https://github.com/hopsoft/stimulus_reflex/pull/344) ([leastbad](https://github.com/leastbad))
16
102
 
17
103
  ## [v3.4.0.pre2](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre2) (2020-11-06)
18
104
 
@@ -60,7 +146,6 @@
60
146
  **Merged pull requests:**
61
147
 
62
148
  - \[docs\] StimulusReflex.debug= on left hand side [\#348](https://github.com/hopsoft/stimulus_reflex/pull/348) ([drnic](https://github.com/drnic))
63
- - Fix page morphs inside Rails engines [\#344](https://github.com/hopsoft/stimulus_reflex/pull/344) ([leastbad](https://github.com/leastbad))
64
149
  - Use Webpacker folder if available [\#343](https://github.com/hopsoft/stimulus_reflex/pull/343) ([coorasse](https://github.com/coorasse))
65
150
  - feat: create a more robust package.json [\#340](https://github.com/hopsoft/stimulus_reflex/pull/340) ([ParamagicDev](https://github.com/ParamagicDev))
66
151
  - Make StimulusReflex configurable and add an initializer [\#339](https://github.com/hopsoft/stimulus_reflex/pull/339) ([RolandStuder](https://github.com/RolandStuder))
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.4.0.pre3)
4
+ stimulus_reflex (3.4.0.pre8)
5
+ cable_ready (>= 4.4)
5
6
  nokogiri
6
7
  rack
7
8
  rails (>= 5.2)
@@ -67,17 +68,17 @@ GEM
67
68
  zeitwerk (~> 2.2, >= 2.2.2)
68
69
  ast (2.4.1)
69
70
  builder (3.2.4)
70
- cable_ready (4.3.0)
71
+ cable_ready (4.4.3)
71
72
  rails (>= 5.2)
72
73
  coderay (1.1.3)
73
74
  concurrent-ruby (1.1.7)
74
75
  crass (1.0.6)
75
- erubi (1.9.0)
76
+ erubi (1.10.0)
76
77
  globalid (0.4.2)
77
78
  activesupport (>= 4.2.0)
78
79
  i18n (1.8.5)
79
80
  concurrent-ruby (~> 1.0)
80
- loofah (2.7.0)
81
+ loofah (2.8.0)
81
82
  crass (~> 1.0.2)
82
83
  nokogiri (>= 1.5.9)
83
84
  mail (2.7.1)
@@ -92,7 +93,7 @@ GEM
92
93
  nio4r (2.5.4)
93
94
  nokogiri (1.10.10)
94
95
  mini_portile2 (~> 2.4.0)
95
- parallel (1.20.0)
96
+ parallel (1.20.1)
96
97
  parser (2.7.2.0)
97
98
  ast (~> 2.4.1)
98
99
  pry (0.12.2)
@@ -131,22 +132,22 @@ GEM
131
132
  thor (>= 0.20.3, < 2.0)
132
133
  rainbow (3.0.0)
133
134
  rake (13.0.1)
134
- redis (4.2.2)
135
- regexp_parser (1.8.2)
135
+ redis (4.2.5)
136
+ regexp_parser (2.0.0)
136
137
  rexml (3.2.4)
137
- rubocop (1.2.0)
138
+ rubocop (1.4.2)
138
139
  parallel (~> 1.10)
139
140
  parser (>= 2.7.1.5)
140
141
  rainbow (>= 2.2.2, < 4.0)
141
142
  regexp_parser (>= 1.8)
142
143
  rexml
143
- rubocop-ast (>= 1.0.1)
144
+ rubocop-ast (>= 1.1.1)
144
145
  ruby-progressbar (~> 1.7)
145
146
  unicode-display_width (>= 1.4.0, < 2.0)
146
- rubocop-ast (1.1.1)
147
+ rubocop-ast (1.3.0)
147
148
  parser (>= 2.7.1.5)
148
- rubocop-performance (1.8.1)
149
- rubocop (>= 0.87.0)
149
+ rubocop-performance (1.9.1)
150
+ rubocop (>= 0.90.0, < 2.0)
150
151
  rubocop-ast (>= 0.4.0)
151
152
  ruby-progressbar (1.10.1)
152
153
  sprockets (4.0.2)
@@ -156,9 +157,9 @@ GEM
156
157
  actionpack (>= 4.0)
157
158
  activesupport (>= 4.0)
158
159
  sprockets (>= 3.0.0)
159
- standard (0.9.0)
160
- rubocop (= 1.2.0)
161
- rubocop-performance (= 1.8.1)
160
+ standard (0.10.1)
161
+ rubocop (= 1.4.2)
162
+ rubocop-performance (= 1.9.1)
162
163
  standardrb (1.0.0)
163
164
  standard
164
165
  thor (1.0.1)
@@ -169,14 +170,13 @@ GEM
169
170
  websocket-driver (0.7.3)
170
171
  websocket-extensions (>= 0.1.0)
171
172
  websocket-extensions (0.1.5)
172
- zeitwerk (2.4.1)
173
+ zeitwerk (2.4.2)
173
174
 
174
175
  PLATFORMS
175
176
  ruby
176
177
 
177
178
  DEPENDENCIES
178
179
  bundler (~> 2.0)
179
- cable_ready (>= 4.3.0)
180
180
  pry
181
181
  pry-nav
182
182
  rake
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="assets/stimulus-reflex-logo-with-copy.svg" width="360" />
2
+ <img src="https://gitcdn.link/repo/hopsoft/stimulus_reflex/master/assets/stimulus-reflex-logo-with-copy.svg" width="360" />
3
3
  <h1 align="center">Welcome to StimulusReflex 👋</h1>
4
4
  <p align="center">
5
5
  <img src="https://img.shields.io/gem/v/stimulus_reflex.svg?color=red" />
@@ -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-1322-brightgreen.svg?style=flat" />
14
+ <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-1600-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" />
@@ -30,9 +30,6 @@
30
30
  <a href="https://www.codacy.com/manual/hopsoft/stimulus_reflex/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=hopsoft/stimulus_reflex&amp;utm_campaign=Badge_Grade" target="_blank">
31
31
  <img alt="Code Quality" src="https://app.codacy.com/project/badge/Grade/d1d72a7060f5467b8696884351cf477f"/>
32
32
  </a>
33
- <a href="https://codeclimate.com/github/hopsoft/stimulus_reflex/maintainability" target="_blank">
34
- <img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/2b24fdbd1ae37a24bedb/maintainability" />
35
- </a>
36
33
  <a target="_blank" rel="noopener noreferrer" href="https://github.com/hopsoft/stimulus_reflex/workflows/Prettier-Standard/badge.svg">
37
34
  <img src="https://github.com/hopsoft/stimulus_reflex/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
38
35
  </a>
@@ -77,7 +74,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
77
74
 
78
75
  ## 👩‍👩‍👧 Discord Community
79
76
 
80
- Please join over 700 of us on [Discord](https://discord.gg/XveN625) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
77
+ Please join over 800 of us on [Discord](https://discord.gg/XveN625) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
81
78
 
82
79
  ![](https://img.shields.io/discord/629472241427415060)
83
80
 
@@ -113,9 +110,8 @@ View the [wiki](https://github.com/hopsoft/stimulus_reflex/wiki/Editor-Configura
113
110
  1. Bump version number at `lib/stimulus_reflex/version.rb`
114
111
  1. Run `rake build`
115
112
  1. Run `rake release`
116
- 1. Change directories `cd ./javascript`
117
- 1. Run `yarn publish` - NOTE: this will throw a fatal error because the tag already exists but the package will still publish
118
-
113
+ 1. Run `yarn publish --no-git-tag-version`
114
+ 1. Commit and push changes to the `package.json` file
119
115
 
120
116
  ## 📝 License
121
117
 
data/Rakefile CHANGED
@@ -3,13 +3,13 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rails/test_unit/runner"
5
5
 
6
- task default: [:test]
7
-
8
- task :test do |task|
9
- return 1 unless system("cd javascript && yarn run test")
10
- Rails::TestUnit::Runner.run
6
+ task :test_javascript do |task|
7
+ system "yarn run test"
11
8
  end
12
9
 
13
10
  task :test_ruby do |task|
14
11
  Rails::TestUnit::Runner.run
15
12
  end
13
+
14
+ task test: [:test_javascript, :test_ruby]
15
+ task default: [:test]
@@ -37,9 +37,14 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
37
37
  element: element,
38
38
  selectors: selectors,
39
39
  method_name: method_name,
40
- permanent_attribute_name: permanent_attribute_name,
41
40
  params: params,
42
- reflex_id: data["reflexId"])
41
+ client_attributes: {
42
+ reflex_id: data["reflexId"],
43
+ xpath: data["xpath"],
44
+ c_xpath: data["cXpath"],
45
+ reflex_controller: data["reflexController"],
46
+ permanent_attribute_name: permanent_attribute_name
47
+ })
43
48
  delegate_call_to_reflex reflex, method_name, arguments
44
49
  rescue => invoke_error
45
50
  message = exception_message_with_backtrace(invoke_error)
@@ -48,7 +53,7 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
48
53
  reflex.rescue_with_handler(invoke_error)
49
54
  reflex.broadcast_message subject: "error", body: body, data: data, error: invoke_error
50
55
  else
51
- logger.error "\e[31m#{body}\e[0m"
56
+ puts "\e[31m#{body}\e[0m"
52
57
  end
53
58
  return
54
59
  end
@@ -63,10 +68,14 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
63
68
  message = exception_message_with_backtrace(render_error)
64
69
  body = "Reflex failed to re-render: #{message} [#{url}]"
65
70
  reflex.broadcast_message subject: "error", body: body, data: data, error: render_error
71
+ puts "\e[31m#{body}\e[0m"
66
72
  end
67
73
  end
68
74
  ensure
69
- commit_session reflex if reflex
75
+ if reflex
76
+ commit_session(reflex)
77
+ reflex.logger.print
78
+ end
70
79
  end
71
80
  end
72
81
 
@@ -101,7 +110,7 @@ class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.cons
101
110
  store.commit_session reflex.request, reflex.controller.response
102
111
  rescue => e
103
112
  message = "Failed to commit session! #{exception_message_with_backtrace(e)}"
104
- logger.error "\e[31m#{message}\e[0m"
113
+ puts "\e[31m#{message}\e[0m"
105
114
  end
106
115
 
107
116
  def exception_message_with_backtrace(exception)
@@ -4,4 +4,5 @@ require "bundler/setup"
4
4
  require "stimulus_reflex"
5
5
  require "pry"
6
6
 
7
+ StimulusReflex.configuration.parent_channel = "ActionCable::Channel::Base"
7
8
  Pry.start
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  bundle exec standardrb --fix
4
- cd ./javascript && yarn run prettier-standard:format
4
+ yarn run prettier-standard:format
@@ -56,12 +56,20 @@ export default class extends ApplicationController {
56
56
  // }
57
57
 
58
58
  // danceSuccess(element, reflex, noop, reflexId) {
59
- // element.innerText = 'Danced like no one was watching! Was someone watching?'
59
+ // element.innerText = '\nDanced like no one was watching! Was someone watching?'
60
60
  // }
61
61
 
62
62
  // danceError(element, reflex, error, reflexId) {
63
63
  // console.error('danceError', error);
64
- // element.innerText = "Couldn't dance!"
64
+ // element.innerText = "\nCouldn\'t dance!"
65
+ // }
66
+
67
+ // afterDance(element, reflex, noop, reflexId) {
68
+ // element.innerText = '\nWhatever that was, it\'s over now.'
69
+ // }
70
+
71
+ // finalizeDance(element, reflex, noop, reflexId) {
72
+ // element.innerText = '\nNow, the cleanup can begin!'
65
73
  // }
66
74
  <% end -%>
67
75
  <% actions.each do |action| -%>
@@ -84,6 +92,10 @@ export default class extends ApplicationController {
84
92
  // <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
85
93
  // console.log("after <%= action %>", element, reflex, reflexId)
86
94
  // }
95
+
96
+ // <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
97
+ // console.log("finalize <%= action %>", element, reflex, reflexId)
98
+ // }
87
99
  <%= "\n" unless action == actions.last -%>
88
100
  <% end -%>
89
101
  }
@@ -39,14 +39,22 @@ export default class extends Controller {
39
39
  }
40
40
 
41
41
  reflexSuccess (element, reflex, noop, reflexId) {
42
- // show success message etc...
42
+ // show success message
43
43
  }
44
44
 
45
45
  reflexError (element, reflex, error, reflexId) {
46
- // show error message etc...
46
+ // show error message
47
+ }
48
+
49
+ reflexHalted (element, reflex, error, reflexId) {
50
+ // handle aborted Reflex action
47
51
  }
48
52
 
49
53
  afterReflex (element, reflex, noop, reflexId) {
50
54
  // document.body.classList.remove('wait')
51
55
  }
56
+
57
+ finalizeReflex (element, reflex, noop, reflexId) {
58
+ // all operations have completed, animation etc is now safe
59
+ }
52
60
  }
@@ -3,24 +3,34 @@
3
3
  class <%= class_name %>Reflex < ApplicationReflex
4
4
  # Add Reflex methods in this file.
5
5
  #
6
- # All Reflex instances expose the following properties:
6
+ # All Reflex instances include CableReady::Broadcaster and expose the following properties:
7
7
  #
8
- # - connection - the ActionCable connection
9
- # - channel - the ActionCable channel
10
- # - request - an ActionDispatch::Request proxy for the socket connection
11
- # - session - the ActionDispatch::Session store for the current visitor
12
- # - url - the URL of the page that triggered the reflex
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)
8
+ # - connection - the ActionCable connection
9
+ # - channel - the ActionCable channel
10
+ # - request - an ActionDispatch::Request proxy for the socket connection
11
+ # - session - the ActionDispatch::Session store for the current visitor
12
+ # - flash - the ActionDispatch::Flash::FlashHash for the current request
13
+ # - url - the URL of the page that triggered the reflex
14
+ # - params - parameters from the element's closest form (if any)
15
+ # - element - a Hash like object that represents the HTML element that triggered the reflex
16
+ # - signed - use a signed Global ID to map dataset attribute to a model eg. element.signed[:foo]
17
+ # - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
18
+ # - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
19
+ # - reflex_id - a UUIDv4 that uniquely identies each Reflex
15
20
  #
16
21
  # Example:
17
22
  #
23
+ # before_reflex do
24
+ # # throw :abort # this will prevent the Reflex from continuing
25
+ # # learn more about callbacks at https://docs.stimulusreflex.com/lifecycle
26
+ # end
27
+ #
18
28
  # def example(argument=true)
19
29
  # # Your logic here...
20
30
  # # Any declared instance variables will be made available to the Rails controller and view.
21
31
  # end
22
32
  #
23
- # Learn more at: https://docs.stimulusreflex.com
33
+ # Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
24
34
 
25
35
  <% actions.each do |action| -%>
26
36
  def <%= action %>