stimulus_reflex 3.3.0.pre4 → 3.3.0.pre5

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: 1c9b7c733ac621d7a767be4d2674f3fc93ba082fd49b2b97bae28f1af426c3a2
4
- data.tar.gz: 2a8c9b669f1b3ae3ca05061fb56fc04ab68c4617d9c90228ce66ea6af929101e
3
+ metadata.gz: cc5d928ba770cb4cb0e167431b216953d3d024f60797ceeba8cb1e941c321f2f
4
+ data.tar.gz: 21ecfef7c3b45524547905728b8dffe13317f76e07685f1c41e9eb59ad20f1aa
5
5
  SHA512:
6
- metadata.gz: 32827f948085f06d9980c806f2392ca59f4c32b39e5512ee8ef69c89c45192abc4de4824a216c2544e49c816ae345bbbf2713d496f6cd07fbefd1f45e94a9ea1
7
- data.tar.gz: b1033c190f6794f2480436ab45da9ba78339dda1cfda7fa2ca724b88186158434dfe36710187bcc36b8fb91433a044ff4585f9deef65178318c95a6e969cf091
6
+ metadata.gz: d89100f1ae64da55040f3ed0435832f593b67ff78631def4bfbf2a02c6eb577b6803ad9ae84760d123e2b5e85a9e52a1d1923a5949b4c76ccdcb82489671d0e4
7
+ data.tar.gz: 7d1c3c338457b2f7c8895726cc381c273aec9c7b65158409dc6e2d7d146cd8d1c51102783dda302e241a207a8c09fd0ebd92b850d96f3bbf0c2e884700bf55e7
@@ -2,11 +2,37 @@
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.3.0.pre3...HEAD)
5
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.3.0.pre4...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Fail loudly if there's a version mismatch between the gem and the npm package. [\#294](https://github.com/hopsoft/stimulus_reflex/issues/294)
10
+
11
+ **Closed issues:**
12
+
13
+ - IE11 Support: "crypto" is undefined [\#308](https://github.com/hopsoft/stimulus_reflex/issues/308)
14
+ - Using `morph` gives error on missing Warden::Manager midddleware? [\#304](https://github.com/hopsoft/stimulus_reflex/issues/304)
15
+ - Update client controller template comments [\#298](https://github.com/hopsoft/stimulus_reflex/issues/298)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - Support IE11 msCrypto \(\#308\) [\#310](https://github.com/hopsoft/stimulus_reflex/pull/310) ([chooselife22](https://github.com/chooselife22))
20
+ - Print warning and exit if caching is disabled or npm/gem versions are mismatched [\#309](https://github.com/hopsoft/stimulus_reflex/pull/309) ([excid3](https://github.com/excid3))
21
+ - ActionCable connectivity events [\#307](https://github.com/hopsoft/stimulus_reflex/pull/307) ([leastbad](https://github.com/leastbad))
22
+ - Copyedits [\#306](https://github.com/hopsoft/stimulus_reflex/pull/306) ([CodingItWrong](https://github.com/CodingItWrong))
23
+ - add redis to cable.yml in development mode [\#305](https://github.com/hopsoft/stimulus_reflex/pull/305) ([leastbad](https://github.com/leastbad))
24
+ - Update morph-modes.md [\#302](https://github.com/hopsoft/stimulus_reflex/pull/302) ([scottbarrow](https://github.com/scottbarrow))
25
+ - Enhance controller templates docs [\#300](https://github.com/hopsoft/stimulus_reflex/pull/300) ([pinzonjulian](https://github.com/pinzonjulian))
26
+ - Avoid mismatching client and server versions [\#297](https://github.com/hopsoft/stimulus_reflex/pull/297) ([piotrwodz](https://github.com/piotrwodz))
27
+
28
+ ## [v3.3.0.pre4](https://github.com/hopsoft/stimulus_reflex/tree/v3.3.0.pre4) (2020-09-13)
29
+
30
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.3.0.pre3...v3.3.0.pre4)
6
31
 
7
32
  **Fixed bugs:**
8
33
 
9
34
  - Lifecycle callbacks do not work [\#281](https://github.com/hopsoft/stimulus_reflex/issues/281)
35
+ - Fix timing issues with post-Reflex lifecycle callbacks [\#299](https://github.com/hopsoft/stimulus_reflex/pull/299) ([leastbad](https://github.com/leastbad))
10
36
 
11
37
  **Closed issues:**
12
38
 
@@ -460,9 +486,7 @@
460
486
  **Implemented enhancements:**
461
487
 
462
488
  - Custom Stimulus schema breaks Reflex [\#91](https://github.com/hopsoft/stimulus_reflex/issues/91)
463
- - Add schema support [\#94](https://github.com/hopsoft/stimulus_reflex/pull/94) ([hopsoft](https://github.com/hopsoft))
464
489
  - inherit stimulus schema [\#92](https://github.com/hopsoft/stimulus_reflex/pull/92) ([nickyvanurk](https://github.com/nickyvanurk))
465
- - Single source of truth [\#76](https://github.com/hopsoft/stimulus_reflex/pull/76) ([leastbad](https://github.com/leastbad))
466
490
 
467
491
  **Fixed bugs:**
468
492
 
@@ -481,6 +505,7 @@
481
505
 
482
506
  **Implemented enhancements:**
483
507
 
508
+ - Single source of truth [\#76](https://github.com/hopsoft/stimulus_reflex/pull/76) ([leastbad](https://github.com/leastbad))
484
509
  - Add CodeFund sponsorship [\#75](https://github.com/hopsoft/stimulus_reflex/pull/75) ([coderberry](https://github.com/coderberry))
485
510
 
486
511
  **Fixed bugs:**
@@ -494,9 +519,11 @@
494
519
  **Implemented enhancements:**
495
520
 
496
521
  - Create Rails generators [\#3](https://github.com/hopsoft/stimulus_reflex/issues/3)
522
+ - Add schema support [\#94](https://github.com/hopsoft/stimulus_reflex/pull/94) ([hopsoft](https://github.com/hopsoft))
497
523
  - Update installer [\#71](https://github.com/hopsoft/stimulus_reflex/pull/71) ([hopsoft](https://github.com/hopsoft))
498
524
  - Tweak generators [\#69](https://github.com/hopsoft/stimulus_reflex/pull/69) ([hopsoft](https://github.com/hopsoft))
499
525
  - add generators [\#67](https://github.com/hopsoft/stimulus_reflex/pull/67) ([andrewmcodes](https://github.com/andrewmcodes))
526
+ - Add reflex name to the lifecycle args [\#62](https://github.com/hopsoft/stimulus_reflex/pull/62) ([hopsoft](https://github.com/hopsoft))
500
527
 
501
528
  **Fixed bugs:**
502
529
 
@@ -525,7 +552,6 @@
525
552
  - Client side call-backs? [\#34](https://github.com/hopsoft/stimulus_reflex/issues/34)
526
553
  - Scoped register\(\)? [\#26](https://github.com/hopsoft/stimulus_reflex/issues/26)
527
554
  - Add guard to verify same URL prior to morph [\#63](https://github.com/hopsoft/stimulus_reflex/pull/63) ([hopsoft](https://github.com/hopsoft))
528
- - Add reflex name to the lifecycle args [\#62](https://github.com/hopsoft/stimulus_reflex/pull/62) ([hopsoft](https://github.com/hopsoft))
529
555
  - Refactor some helper methods out of main file [\#61](https://github.com/hopsoft/stimulus_reflex/pull/61) ([hopsoft](https://github.com/hopsoft))
530
556
  - Documentation update [\#58](https://github.com/hopsoft/stimulus_reflex/pull/58) ([leastbad](https://github.com/leastbad))
531
557
  - \# Support for data-reflex-permanent [\#57](https://github.com/hopsoft/stimulus_reflex/pull/57) ([hopsoft](https://github.com/hopsoft))
@@ -1,65 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.3.0.pre3)
4
+ stimulus_reflex (3.3.0.pre4)
5
5
  cable_ready (>= 4.1.2)
6
6
  nokogiri
7
7
  rack
8
8
  rails (>= 5.2)
9
+ redis
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- actioncable (6.0.3.2)
14
- actionpack (= 6.0.3.2)
14
+ actioncable (6.0.3.3)
15
+ actionpack (= 6.0.3.3)
15
16
  nio4r (~> 2.0)
16
17
  websocket-driver (>= 0.6.1)
17
- actionmailbox (6.0.3.2)
18
- actionpack (= 6.0.3.2)
19
- activejob (= 6.0.3.2)
20
- activerecord (= 6.0.3.2)
21
- activestorage (= 6.0.3.2)
22
- activesupport (= 6.0.3.2)
18
+ actionmailbox (6.0.3.3)
19
+ actionpack (= 6.0.3.3)
20
+ activejob (= 6.0.3.3)
21
+ activerecord (= 6.0.3.3)
22
+ activestorage (= 6.0.3.3)
23
+ activesupport (= 6.0.3.3)
23
24
  mail (>= 2.7.1)
24
- actionmailer (6.0.3.2)
25
- actionpack (= 6.0.3.2)
26
- actionview (= 6.0.3.2)
27
- activejob (= 6.0.3.2)
25
+ actionmailer (6.0.3.3)
26
+ actionpack (= 6.0.3.3)
27
+ actionview (= 6.0.3.3)
28
+ activejob (= 6.0.3.3)
28
29
  mail (~> 2.5, >= 2.5.4)
29
30
  rails-dom-testing (~> 2.0)
30
- actionpack (6.0.3.2)
31
- actionview (= 6.0.3.2)
32
- activesupport (= 6.0.3.2)
31
+ actionpack (6.0.3.3)
32
+ actionview (= 6.0.3.3)
33
+ activesupport (= 6.0.3.3)
33
34
  rack (~> 2.0, >= 2.0.8)
34
35
  rack-test (>= 0.6.3)
35
36
  rails-dom-testing (~> 2.0)
36
37
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
- actiontext (6.0.3.2)
38
- actionpack (= 6.0.3.2)
39
- activerecord (= 6.0.3.2)
40
- activestorage (= 6.0.3.2)
41
- activesupport (= 6.0.3.2)
38
+ actiontext (6.0.3.3)
39
+ actionpack (= 6.0.3.3)
40
+ activerecord (= 6.0.3.3)
41
+ activestorage (= 6.0.3.3)
42
+ activesupport (= 6.0.3.3)
42
43
  nokogiri (>= 1.8.5)
43
- actionview (6.0.3.2)
44
- activesupport (= 6.0.3.2)
44
+ actionview (6.0.3.3)
45
+ activesupport (= 6.0.3.3)
45
46
  builder (~> 3.1)
46
47
  erubi (~> 1.4)
47
48
  rails-dom-testing (~> 2.0)
48
49
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
- activejob (6.0.3.2)
50
- activesupport (= 6.0.3.2)
50
+ activejob (6.0.3.3)
51
+ activesupport (= 6.0.3.3)
51
52
  globalid (>= 0.3.6)
52
- activemodel (6.0.3.2)
53
- activesupport (= 6.0.3.2)
54
- activerecord (6.0.3.2)
55
- activemodel (= 6.0.3.2)
56
- activesupport (= 6.0.3.2)
57
- activestorage (6.0.3.2)
58
- actionpack (= 6.0.3.2)
59
- activejob (= 6.0.3.2)
60
- activerecord (= 6.0.3.2)
53
+ activemodel (6.0.3.3)
54
+ activesupport (= 6.0.3.3)
55
+ activerecord (6.0.3.3)
56
+ activemodel (= 6.0.3.3)
57
+ activesupport (= 6.0.3.3)
58
+ activestorage (6.0.3.3)
59
+ actionpack (= 6.0.3.3)
60
+ activejob (= 6.0.3.3)
61
+ activerecord (= 6.0.3.3)
61
62
  marcel (~> 0.3.1)
62
- activesupport (6.0.3.2)
63
+ activesupport (6.0.3.3)
63
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
65
  i18n (>= 0.7, < 2)
65
66
  minitest (~> 5.1)
@@ -88,8 +89,8 @@ GEM
88
89
  mimemagic (0.3.5)
89
90
  mini_mime (1.0.2)
90
91
  mini_portile2 (2.4.0)
91
- minitest (5.14.1)
92
- nio4r (2.5.2)
92
+ minitest (5.14.2)
93
+ nio4r (2.5.4)
93
94
  nokogiri (1.10.10)
94
95
  mini_portile2 (~> 2.4.0)
95
96
  parallel (1.19.2)
@@ -103,34 +104,35 @@ GEM
103
104
  rack (2.2.3)
104
105
  rack-test (1.1.0)
105
106
  rack (>= 1.0, < 3)
106
- rails (6.0.3.2)
107
- actioncable (= 6.0.3.2)
108
- actionmailbox (= 6.0.3.2)
109
- actionmailer (= 6.0.3.2)
110
- actionpack (= 6.0.3.2)
111
- actiontext (= 6.0.3.2)
112
- actionview (= 6.0.3.2)
113
- activejob (= 6.0.3.2)
114
- activemodel (= 6.0.3.2)
115
- activerecord (= 6.0.3.2)
116
- activestorage (= 6.0.3.2)
117
- activesupport (= 6.0.3.2)
107
+ rails (6.0.3.3)
108
+ actioncable (= 6.0.3.3)
109
+ actionmailbox (= 6.0.3.3)
110
+ actionmailer (= 6.0.3.3)
111
+ actionpack (= 6.0.3.3)
112
+ actiontext (= 6.0.3.3)
113
+ actionview (= 6.0.3.3)
114
+ activejob (= 6.0.3.3)
115
+ activemodel (= 6.0.3.3)
116
+ activerecord (= 6.0.3.3)
117
+ activestorage (= 6.0.3.3)
118
+ activesupport (= 6.0.3.3)
118
119
  bundler (>= 1.3.0)
119
- railties (= 6.0.3.2)
120
+ railties (= 6.0.3.3)
120
121
  sprockets-rails (>= 2.0.0)
121
122
  rails-dom-testing (2.0.3)
122
123
  activesupport (>= 4.2.0)
123
124
  nokogiri (>= 1.6)
124
125
  rails-html-sanitizer (1.3.0)
125
126
  loofah (~> 2.3)
126
- railties (6.0.3.2)
127
- actionpack (= 6.0.3.2)
128
- activesupport (= 6.0.3.2)
127
+ railties (6.0.3.3)
128
+ actionpack (= 6.0.3.3)
129
+ activesupport (= 6.0.3.3)
129
130
  method_source
130
131
  rake (>= 0.8.7)
131
132
  thor (>= 0.20.3, < 2.0)
132
133
  rainbow (3.0.0)
133
134
  rake (13.0.1)
135
+ redis (4.2.2)
134
136
  regexp_parser (1.7.1)
135
137
  rexml (3.2.4)
136
138
  rubocop (0.89.1)
@@ -150,7 +152,7 @@ GEM
150
152
  sprockets (4.0.2)
151
153
  concurrent-ruby (~> 1.0)
152
154
  rack (> 1, < 3)
153
- sprockets-rails (3.2.1)
155
+ sprockets-rails (3.2.2)
154
156
  actionpack (>= 4.0)
155
157
  activesupport (>= 4.0)
156
158
  sprockets (>= 3.0.0)
data/README.md CHANGED
@@ -74,7 +74,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
74
74
 
75
75
  ## 👩‍👩‍👧 Discord Community
76
76
 
77
- Please join over 350 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 500 of us on [Discord](https://discord.gg/XveN625) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
78
78
 
79
79
  ![](https://img.shields.io/discord/629472241427415060)
80
80
 
@@ -1,56 +1,88 @@
1
1
  import ApplicationController from './application_controller'
2
2
 
3
- /* This is the custom StimulusReflex controller for <%= class_name %>Reflex.
3
+ /* This is the custom StimulusReflex controller for the <%= class_name %> Reflex.
4
4
  * Learn more at: https://docs.stimulusreflex.com
5
5
  */
6
6
  export default class extends ApplicationController {
7
+ /*
8
+ * Regular Stimulus lifecycle methods
9
+ * Learn more at: https://stimulusjs.org/reference/lifecycle-callbacks
10
+ *
11
+ * If you intend to use this controller as a regular stimulus controller as well,
12
+ * make sure any Stimulus lifecycle methods overridden in ApplicationController call super.
13
+ *
14
+ * Important:
15
+ * By default, StimulusReflex overrides the -connect- method so make sure you
16
+ * call super if you intend to do anything else when this controller connects.
17
+ */
18
+
19
+ connect () {
20
+ super.connect()
21
+ // add your code here, if applicable
22
+ }
23
+
7
24
  /* Reflex specific lifecycle methods.
8
- * Use methods similar to this example to handle lifecycle concerns for a specific Reflex method.
9
- * Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
25
+ *
26
+ * For every method defined in your Reflex class, a matching set of lifecycle methods become available
27
+ * in this javascript controller. These are optional, so feel free to delete these stubs if you don't
28
+ * need them.
29
+ *
30
+ * Important:
31
+ * Make sure to add data-controller="<%= class_name.underscore.dasherize %>" to your markup alongside
32
+ * data-reflex="<%= class_name %>#dance" for the lifecycle methods to fire properly.
10
33
  *
11
34
  * Example:
12
35
  *
13
- * <a href="#" data-reflex="<%= class_name %>Reflex#example">Example</a>
36
+ * <a href="#" data-reflex="click-><%= class_name %>#dance" data-controller="<%= class_name.underscore.dasherize %>">Dance!</a>
14
37
  *
15
38
  * Arguments:
16
39
  *
17
40
  * element - the element that triggered the reflex
18
41
  * may be different than the Stimulus controller's this.element
19
42
  *
20
- * reflex - the name of the reflex e.g. "<%= class_name %>Reflex#example"
43
+ * reflex - the name of the reflex e.g. "<%= class_name %>#dance"
44
+ *
45
+ * error/noop - the error message (for reflexError), otherwise null
21
46
  *
22
- * error - error message from the server
47
+ * reflexId - a UUID4 or developer-provided unique identifier for each Reflex
23
48
  */
24
49
 
25
50
  <% if actions.empty? -%>
26
- // beforeUpdate(element, reflex) {
27
- // element.innerText = 'Updating...'
51
+ // Assuming you create a "<%= class_name %>#dance" action in your Reflex class
52
+ // you'll be able to use the following lifecycle methods:
53
+
54
+ // beforeDance(element, reflex, noop, reflexId) {
55
+ // element.innerText = 'Putting dance shoes on...'
28
56
  // }
29
57
 
30
- // updateSuccess(element, reflex) {
31
- // element.innerText = 'Updated Successfully.'
58
+ // danceSuccess(element, reflex, noop, reflexId) {
59
+ // element.innerText = 'Danced like no one was watching! Was someone watching?'
32
60
  // }
33
61
 
34
- // updateError(element, reflex, error) {
35
- // console.error('updateError', error);
36
- // element.innerText = 'Update Failed!'
62
+ // danceError(element, reflex, error, reflexId) {
63
+ // console.error('danceError', error);
64
+ // element.innerText = "Couldn't dance!"
37
65
  // }
38
66
  <% end -%>
39
67
  <% actions.each do |action| -%>
40
- // <%= "before_#{action}".camelize(:lower) %>(element, reflex) {
41
- // console.log("before <%= action %>", element, reflex)
68
+ // <%= "before_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
69
+ // console.log("before <%= action %>", element, reflex, reflexId)
70
+ // }
71
+
72
+ // <%= "#{action}_success".camelize(:lower) %>(element, reflex, noop, reflexId) {
73
+ // console.log("<%= action %> success", element, reflex, reflexId)
42
74
  // }
43
75
 
44
- // <%= "#{action}_success".camelize(:lower) %>(element, reflex) {
45
- // console.log("<%= action %> success", element, reflex)
76
+ // <%= "#{action}_error".camelize(:lower) %>(element, reflex, error, reflexId) {
77
+ // console.error("<%= action %> error", element, reflex, error, reflexId)
46
78
  // }
47
79
 
48
- // <%= "#{action}_error".camelize(:lower) %>(element, reflex, error) {
49
- // console.error("<%= action %> error", element, reflex, error)
80
+ // <%= "#{action}_halted".camelize(:lower) %>(element, reflex, noop, reflexId) {
81
+ // console.warn("<%= action %> halted", element, reflex, reflexId)
50
82
  // }
51
83
 
52
- // <%= "after_#{action}".camelize(:lower) %>(element, reflex, error) {
53
- // console.log("after <%= action %>", element, reflex, error)
84
+ // <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
85
+ // console.log("after <%= action %>", element, reflex, reflexId)
54
86
  // }
55
87
  <%= "\n" unless action == actions.last -%>
56
88
  <% end -%>
@@ -1,7 +1,7 @@
1
1
  import { Controller } from 'stimulus'
2
2
  import StimulusReflex from 'stimulus_reflex'
3
3
 
4
- /* This is your application's ApplicationController.
4
+ /* This is your ApplicationController.
5
5
  * All StimulusReflex controllers should inherit from this class.
6
6
  *
7
7
  * Example:
@@ -17,7 +17,8 @@ export default class extends Controller {
17
17
  StimulusReflex.register(this)
18
18
  }
19
19
 
20
- /* Application wide lifecycle methods.
20
+ /* Application-wide lifecycle methods
21
+ *
21
22
  * Use these methods to handle lifecycle concerns for the entire application.
22
23
  * Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
23
24
  *
@@ -26,24 +27,26 @@ export default class extends Controller {
26
27
  * element - the element that triggered the reflex
27
28
  * may be different than the Stimulus controller's this.element
28
29
  *
29
- * reflex - the name of the reflex e.g. "ExampleReflex#demo"
30
+ * reflex - the name of the reflex e.g. "Example#demo"
31
+ *
32
+ * error/noop - the error message (for reflexError), otherwise null
30
33
  *
31
- * error - error message from the server
34
+ * reflexId - a UUID4 or developer-provided unique identifier for each Reflex
32
35
  */
33
36
 
34
- beforeReflex (element, reflex) {
37
+ beforeReflex (element, reflex, noop, reflexId) {
35
38
  // document.body.classList.add('wait')
36
39
  }
37
40
 
38
- reflexSuccess (element, reflex, error) {
41
+ reflexSuccess (element, reflex, noop, reflexId) {
39
42
  // show success message etc...
40
43
  }
41
44
 
42
- reflexError (element, reflex, error) {
45
+ reflexError (element, reflex, error, reflexId) {
43
46
  // show error message etc...
44
47
  }
45
48
 
46
- afterReflex (element, reflex) {
49
+ afterReflex (element, reflex, noop, reflexId) {
47
50
  // document.body.classList.remove('wait')
48
51
  }
49
52
  }
@@ -20,5 +20,68 @@ require "generators/stimulus_reflex_generator"
20
20
 
21
21
  module StimulusReflex
22
22
  class Engine < Rails::Engine
23
+ NODE_VERSION_FORMAT = /(\d\.\d\.\d.*):/
24
+ JSON_VERSION_FORMAT = /(\d\.\d\.\d.*)\"/
25
+
26
+ initializer "stimulus_reflex.verify_caching_enabled" do
27
+ unless caching_enabled?
28
+ puts <<~WARN
29
+ Stimulus Reflex requires caching to be enabled. Caching allows the session to be modified during ActionCable requests.
30
+ To enable caching in development, run:
31
+
32
+ rails dev:cache
33
+ WARN
34
+ exit
35
+ end
36
+ end
37
+
38
+ initializer "stimulus_reflex.verify_npm_package_version" do
39
+ unless node_version_matches?
40
+ puts <<~WARN
41
+ The Stimulus Reflex javascript package version (#{node_package_version}) does not match the Rubygem version (#{gem_version}).
42
+ To update the Stimulus Reflex node module:
43
+
44
+ yarn upgrade stimulus_reflex@#{gem_version}
45
+ WARN
46
+ exit
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def caching_enabled?
53
+ Rails.application.config.action_controller.perform_caching &&
54
+ Rails.application.config.cache_store != :null_store
55
+ end
56
+
57
+ def node_version_matches?
58
+ node_package_version == gem_version
59
+ end
60
+
61
+ def gem_version
62
+ StimulusReflex::VERSION.gsub(".pre", "-pre")
63
+ end
64
+
65
+ def node_package_version
66
+ match = File.foreach(yarn_lock_path).grep(/^stimulus_reflex/)
67
+ return match.first[NODE_VERSION_FORMAT, 1] if match.present?
68
+
69
+ match = File.foreach(yarn_link_path).grep(/version/)
70
+ return match.first[JSON_VERSION_FORMAT, 1] if match.present?
71
+
72
+ puts <<~WARN
73
+ Can't locate the stimulus_reflex NPM package.
74
+ Either add it to your package.json as a dependency or use "yarn link stimulus_reflex" if you are doing development.
75
+ WARN
76
+ exit
77
+ end
78
+
79
+ def yarn_lock_path
80
+ Rails.root.join("yarn.lock")
81
+ end
82
+
83
+ def yarn_link_path
84
+ Rails.root.join("node_modules", "stimulus_reflex", "package.json")
85
+ end
23
86
  end
24
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "3.3.0.pre4"
4
+ VERSION = "3.3.0.pre5"
5
5
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
+ require "stimulus_reflex/version"
4
5
 
5
6
  namespace :stimulus_reflex do
6
7
  desc "Install StimulusReflex in this application"
7
8
  task install: :environment do
8
9
  system "bundle exec rails webpacker:install:stimulus"
9
- system "yarn add stimulus_reflex"
10
+ gem_version = StimulusReflex::VERSION.gsub(".pre", "-pre")
11
+ system "yarn add stimulus_reflex@#{gem_version}"
10
12
 
11
13
  FileUtils.mkdir_p Rails.root.join("app/javascript/controllers"), verbose: true
12
14
  FileUtils.mkdir_p Rails.root.join("app/reflexes"), verbose: true
@@ -50,6 +52,16 @@ namespace :stimulus_reflex do
50
52
  File.open(filepath, "w") { |f| f.write lines.join }
51
53
  end
52
54
 
55
+ filepath = Rails.root.join("config/cable.yml")
56
+ lines = File.open(filepath, "r") { |f| f.readlines }
57
+ if lines[1].include?("adapter: async")
58
+ lines.delete_at 1
59
+ lines.insert 1, " adapter: redis\n"
60
+ lines.insert 2, " url: <%= ENV.fetch(\"REDIS_URL\") { \"redis://localhost:6379/1\" } %>\n"
61
+ lines.insert 3, " channel_prefix: " + Rails.application.class.module_parent.to_s.underscore + "_development\n"
62
+ File.open(filepath, "w") { |f| f.write lines.join }
63
+ end
64
+
53
65
  system "bundle exec rails generate stimulus_reflex example"
54
66
  system "rails dev:cache" unless Rails.root.join("tmp", "caching-dev.txt").exist?
55
67
  end
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.3.0.pre4
4
+ version: 3.3.0.pre5
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-09-13 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack