stimulus_reflex 3.4.0.pre0 → 3.4.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 +4 -4
- data/CHANGELOG.md +77 -3
- data/Gemfile.lock +12 -12
- data/README.md +6 -7
- data/Rakefile +1 -1
- data/app/channels/stimulus_reflex/channel.rb +125 -0
- data/bin/standardize +1 -1
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +13 -2
- data/lib/stimulus_reflex.rb +2 -0
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +9 -2
- data/lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb +4 -0
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +6 -1
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +10 -0
- data/lib/stimulus_reflex/configuration.rb +5 -2
- data/lib/stimulus_reflex/logger.rb +106 -0
- data/lib/stimulus_reflex/reflex.rb +8 -4
- data/lib/stimulus_reflex/sanity_checker.rb +53 -11
- data/lib/stimulus_reflex/utils/colorize.rb +23 -0
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +3 -2
- data/package.json +11 -17
- data/stimulus_reflex.gemspec +2 -2
- data/test/broadcasters/broadcaster_test.rb +15 -0
- data/test/broadcasters/nothing_broadcaster_test.rb +34 -0
- data/test/broadcasters/page_broadcaster_test.rb +69 -0
- data/test/broadcasters/selector_broadcaster_test.rb +83 -0
- data/test/test_helper.rb +2 -0
- data/test/tmp/app/reflexes/{user_reflex.rb → posts_reflex.rb} +1 -10
- data/yarn.lock +248 -1798
- metadata +21 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1744cbfb7c9c5508487beb3d0087c77b6cc532386ef503709aa0c0097b4f56e
|
4
|
+
data.tar.gz: 99ce8b8d1ad3190d5cd90e49182b39ec959a39f3accb4784f2d0cccbfb7e6fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faccf3117f5cb17303725bab3ba659a77314e44908a1b5d1d5184e171b2635c44a10a42f7e19cbfefa6231a6488d1364b6b463a04e3438e1b92aff237545d515
|
7
|
+
data.tar.gz: 126a3dc45916880d97b6ab1971dfb2a433b1d8e1c27b3c7a1c32a5d0b55ee0ae7c50bfdb9b10901525520b0ae1e975a083125a26305147e62252464a872b15db
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,81 @@
|
|
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.
|
5
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre4...HEAD)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- SR doesn't seem to handle redirects / 302s [\#376](https://github.com/hopsoft/stimulus_reflex/issues/376)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Move package.json to root of project [\#380](https://github.com/hopsoft/stimulus_reflex/pull/380) ([hopsoft](https://github.com/hopsoft))
|
14
|
+
- make element.reflexController a dictionary [\#379](https://github.com/hopsoft/stimulus_reflex/pull/379) ([existentialmutt](https://github.com/existentialmutt))
|
15
|
+
- fixed bug preventing callbacks for multiple morphs [\#378](https://github.com/hopsoft/stimulus_reflex/pull/378) ([leastbad](https://github.com/leastbad))
|
16
|
+
- 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))
|
17
|
+
- Exit with nonzero status code [\#375](https://github.com/hopsoft/stimulus_reflex/pull/375) ([julianrubisch](https://github.com/julianrubisch))
|
18
|
+
|
19
|
+
## [v3.4.0.pre4](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre4) (2020-11-19)
|
20
|
+
|
21
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre3...v3.4.0.pre4)
|
22
|
+
|
23
|
+
**Fixed bugs:**
|
24
|
+
|
25
|
+
- 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))
|
26
|
+
- fix nothing morphs and error messages [\#368](https://github.com/hopsoft/stimulus_reflex/pull/368) ([leastbad](https://github.com/leastbad))
|
27
|
+
|
28
|
+
**Closed issues:**
|
29
|
+
|
30
|
+
- `stimulus\_reflex:install` fails to complete in Rails 5.2 [\#367](https://github.com/hopsoft/stimulus_reflex/issues/367)
|
31
|
+
- Form data still not captured [\#366](https://github.com/hopsoft/stimulus_reflex/issues/366)
|
32
|
+
- Console exception when reflex does not update a page that didn't trigger the reflex [\#363](https://github.com/hopsoft/stimulus_reflex/issues/363)
|
33
|
+
- Improve server-side logging options [\#264](https://github.com/hopsoft/stimulus_reflex/issues/264)
|
34
|
+
|
35
|
+
**Merged pull requests:**
|
36
|
+
|
37
|
+
- 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))
|
38
|
+
- Improve logged post\_install.js message [\#372](https://github.com/hopsoft/stimulus_reflex/pull/372) ([forsbergplustwo](https://github.com/forsbergplustwo))
|
39
|
+
- Pass additional reflex-related data to reflex from data [\#370](https://github.com/hopsoft/stimulus_reflex/pull/370) ([joshleblanc](https://github.com/joshleblanc))
|
40
|
+
- fix: rip out microbundle [\#369](https://github.com/hopsoft/stimulus_reflex/pull/369) ([ParamagicDev](https://github.com/ParamagicDev))
|
41
|
+
- Add tests for broadcasters [\#364](https://github.com/hopsoft/stimulus_reflex/pull/364) ([julianrubisch](https://github.com/julianrubisch))
|
42
|
+
- 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))
|
43
|
+
- fix: revert CR and @rails/actioncable to dependencies [\#361](https://github.com/hopsoft/stimulus_reflex/pull/361) ([ParamagicDev](https://github.com/ParamagicDev))
|
44
|
+
- xpath fix [\#360](https://github.com/hopsoft/stimulus_reflex/pull/360) ([leastbad](https://github.com/leastbad))
|
45
|
+
|
46
|
+
## [v3.4.0.pre3](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre3) (2020-11-11)
|
47
|
+
|
48
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre2...v3.4.0.pre3)
|
49
|
+
|
50
|
+
**Merged pull requests:**
|
51
|
+
|
52
|
+
- Allow to supress warnings for sanity checks [\#359](https://github.com/hopsoft/stimulus_reflex/pull/359) ([RolandStuder](https://github.com/RolandStuder))
|
53
|
+
- serializeForm: only append given input if element is submit button [\#357](https://github.com/hopsoft/stimulus_reflex/pull/357) ([marcoroth](https://github.com/marcoroth))
|
54
|
+
- Update package.json to 3.4.0-pre2 [\#356](https://github.com/hopsoft/stimulus_reflex/pull/356) ([marcoroth](https://github.com/marcoroth))
|
55
|
+
- Fix elementToXPath import [\#355](https://github.com/hopsoft/stimulus_reflex/pull/355) ([julianrubisch](https://github.com/julianrubisch))
|
56
|
+
- Add guard clause to return valid empty form data [\#354](https://github.com/hopsoft/stimulus_reflex/pull/354) ([julianrubisch](https://github.com/julianrubisch))
|
57
|
+
- simplify xpath functions [\#353](https://github.com/hopsoft/stimulus_reflex/pull/353) ([leastbad](https://github.com/leastbad))
|
58
|
+
- pass reflex id to reflex [\#352](https://github.com/hopsoft/stimulus_reflex/pull/352) ([joshleblanc](https://github.com/joshleblanc))
|
59
|
+
|
60
|
+
## [v3.4.0.pre2](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre2) (2020-11-06)
|
61
|
+
|
62
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre1...v3.4.0.pre2)
|
63
|
+
|
64
|
+
**Closed issues:**
|
65
|
+
|
66
|
+
- Regression in version 3.4.0-pre1: Cannot find module `cable\_ready` [\#350](https://github.com/hopsoft/stimulus_reflex/issues/350)
|
67
|
+
|
68
|
+
**Merged pull requests:**
|
69
|
+
|
70
|
+
- move `cable\_ready` to development dependencies [\#351](https://github.com/hopsoft/stimulus_reflex/pull/351) ([marcoroth](https://github.com/marcoroth))
|
71
|
+
- Fix serializeForm initialization [\#349](https://github.com/hopsoft/stimulus_reflex/pull/349) ([marcoroth](https://github.com/marcoroth))
|
72
|
+
|
73
|
+
## [v3.4.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre1) (2020-11-03)
|
74
|
+
|
75
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre0...v3.4.0.pre1)
|
76
|
+
|
77
|
+
## [v3.4.0.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre0) (2020-11-02)
|
78
|
+
|
79
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.3.0...v3.4.0.pre0)
|
6
80
|
|
7
81
|
**Implemented enhancements:**
|
8
82
|
|
@@ -334,8 +408,7 @@
|
|
334
408
|
|
335
409
|
**Fixed bugs:**
|
336
410
|
|
337
|
-
- Pluralize the generated class name, so that will match with the file name [\#178](https://github.com/hopsoft/stimulus_reflex/pull/178) ([
|
338
|
-
- Remove unneeded registerConsumer logic [\#158](https://github.com/hopsoft/stimulus_reflex/pull/158) ([hopsoft](https://github.com/hopsoft))
|
411
|
+
- Pluralize the generated class name, so that will match with the file name [\#178](https://github.com/hopsoft/stimulus_reflex/pull/178) ([dark88888](https://github.com/dark88888))
|
339
412
|
|
340
413
|
**Closed issues:**
|
341
414
|
|
@@ -389,6 +462,7 @@
|
|
389
462
|
**Fixed bugs:**
|
390
463
|
|
391
464
|
- Unable to register the ActionCable Consumer [\#156](https://github.com/hopsoft/stimulus_reflex/issues/156)
|
465
|
+
- Remove unneeded registerConsumer logic [\#158](https://github.com/hopsoft/stimulus_reflex/pull/158) ([hopsoft](https://github.com/hopsoft))
|
392
466
|
|
393
467
|
**Closed issues:**
|
394
468
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (3.4.0.
|
4
|
+
stimulus_reflex (3.4.0.pre5)
|
5
5
|
cable_ready (>= 4.3.0)
|
6
6
|
nokogiri
|
7
7
|
rack
|
@@ -68,12 +68,12 @@ GEM
|
|
68
68
|
zeitwerk (~> 2.2, >= 2.2.2)
|
69
69
|
ast (2.4.1)
|
70
70
|
builder (3.2.4)
|
71
|
-
cable_ready (4.
|
71
|
+
cable_ready (4.4.0)
|
72
72
|
rails (>= 5.2)
|
73
73
|
coderay (1.1.3)
|
74
74
|
concurrent-ruby (1.1.7)
|
75
75
|
crass (1.0.6)
|
76
|
-
erubi (1.
|
76
|
+
erubi (1.10.0)
|
77
77
|
globalid (0.4.2)
|
78
78
|
activesupport (>= 4.2.0)
|
79
79
|
i18n (1.8.5)
|
@@ -93,7 +93,7 @@ GEM
|
|
93
93
|
nio4r (2.5.4)
|
94
94
|
nokogiri (1.10.10)
|
95
95
|
mini_portile2 (~> 2.4.0)
|
96
|
-
parallel (1.
|
96
|
+
parallel (1.20.1)
|
97
97
|
parser (2.7.2.0)
|
98
98
|
ast (~> 2.4.1)
|
99
99
|
pry (0.12.2)
|
@@ -132,19 +132,19 @@ GEM
|
|
132
132
|
thor (>= 0.20.3, < 2.0)
|
133
133
|
rainbow (3.0.0)
|
134
134
|
rake (13.0.1)
|
135
|
-
redis (4.2.
|
136
|
-
regexp_parser (
|
135
|
+
redis (4.2.5)
|
136
|
+
regexp_parser (2.0.0)
|
137
137
|
rexml (3.2.4)
|
138
|
-
rubocop (1.
|
138
|
+
rubocop (1.2.0)
|
139
139
|
parallel (~> 1.10)
|
140
140
|
parser (>= 2.7.1.5)
|
141
141
|
rainbow (>= 2.2.2, < 4.0)
|
142
142
|
regexp_parser (>= 1.8)
|
143
143
|
rexml
|
144
|
-
rubocop-ast (>= 0.
|
144
|
+
rubocop-ast (>= 1.0.1)
|
145
145
|
ruby-progressbar (~> 1.7)
|
146
146
|
unicode-display_width (>= 1.4.0, < 2.0)
|
147
|
-
rubocop-ast (1.
|
147
|
+
rubocop-ast (1.2.0)
|
148
148
|
parser (>= 2.7.1.5)
|
149
149
|
rubocop-performance (1.8.1)
|
150
150
|
rubocop (>= 0.87.0)
|
@@ -157,14 +157,14 @@ GEM
|
|
157
157
|
actionpack (>= 4.0)
|
158
158
|
activesupport (>= 4.0)
|
159
159
|
sprockets (>= 3.0.0)
|
160
|
-
standard (0.
|
161
|
-
rubocop (= 1.
|
160
|
+
standard (0.9.0)
|
161
|
+
rubocop (= 1.2.0)
|
162
162
|
rubocop-performance (= 1.8.1)
|
163
163
|
standardrb (1.0.0)
|
164
164
|
standard
|
165
165
|
thor (1.0.1)
|
166
166
|
thread_safe (0.3.6)
|
167
|
-
tzinfo (1.2.
|
167
|
+
tzinfo (1.2.8)
|
168
168
|
thread_safe (~> 0.1)
|
169
169
|
unicode-display_width (1.7.0)
|
170
170
|
websocket-driver (0.7.3)
|
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-
|
14
|
+
<img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-1506-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" />
|
@@ -54,7 +54,7 @@ And, it's fast.
|
|
54
54
|
|
55
55
|
It works seamlessly with the Rails tooling you already know and love.
|
56
56
|
|
57
|
-
- Server-rendered HTML, delivered in
|
57
|
+
- Server-rendered HTML, delivered in milliseconds over the wire via Websockets
|
58
58
|
- ERB templates and partials, with first-class [ViewComponent](https://github.com/github/view_component) support
|
59
59
|
- [Russian doll caching](https://edgeguides.rubyonrails.org/caching_with_rails.html#russian-doll-caching) and [ActiveJob](https://guides.rubyonrails.org/active_job_basics.html)
|
60
60
|
- [StimulusJS](https://stimulusjs.org/) and [Turbolinks](https://www.youtube.com/watch?v=SWEts0rlezA)
|
@@ -77,7 +77,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
|
|
77
77
|
|
78
78
|
## 👩👩👧 Discord Community
|
79
79
|
|
80
|
-
Please join over
|
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.
|
81
81
|
|
82
82
|
![](https://img.shields.io/discord/629472241427415060)
|
83
83
|
|
@@ -113,9 +113,8 @@ View the [wiki](https://github.com/hopsoft/stimulus_reflex/wiki/Editor-Configura
|
|
113
113
|
1. Bump version number at `lib/stimulus_reflex/version.rb`
|
114
114
|
1. Run `rake build`
|
115
115
|
1. Run `rake release`
|
116
|
-
1.
|
117
|
-
1.
|
118
|
-
|
116
|
+
1. Run `yarn publish --no-git-tag-version`
|
117
|
+
1. Commit and push changes to the `package.json` file
|
119
118
|
|
120
119
|
## 📝 License
|
121
120
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.constantize
|
4
|
+
def stream_name
|
5
|
+
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
6
|
+
[
|
7
|
+
params[:channel],
|
8
|
+
ids.select(&:present?).join(";")
|
9
|
+
].select(&:present?).join(":")
|
10
|
+
end
|
11
|
+
|
12
|
+
def subscribed
|
13
|
+
super
|
14
|
+
fix_environment!
|
15
|
+
stream_from stream_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def receive(data)
|
19
|
+
url = data["url"].to_s
|
20
|
+
selectors = (data["selectors"] || []).select(&:present?)
|
21
|
+
selectors = data["selectors"] = ["body"] if selectors.blank?
|
22
|
+
target = data["target"].to_s
|
23
|
+
reflex_name, method_name = target.split("#")
|
24
|
+
reflex_name = reflex_name.camelize
|
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
|
+
permanent_attribute_name = data["permanentAttributeName"]
|
29
|
+
form_data = Rack::Utils.parse_nested_query(data["formData"])
|
30
|
+
params = form_data.deep_merge(data["params"] || {})
|
31
|
+
|
32
|
+
begin
|
33
|
+
begin
|
34
|
+
reflex_class = reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
|
35
|
+
reflex = reflex_class.new(self,
|
36
|
+
url: url,
|
37
|
+
element: element,
|
38
|
+
selectors: selectors,
|
39
|
+
method_name: method_name,
|
40
|
+
params: params,
|
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
|
+
})
|
48
|
+
delegate_call_to_reflex reflex, method_name, arguments
|
49
|
+
rescue => invoke_error
|
50
|
+
message = exception_message_with_backtrace(invoke_error)
|
51
|
+
body = "Reflex #{target} failed: #{message} [#{url}]"
|
52
|
+
if reflex
|
53
|
+
reflex.rescue_with_handler(invoke_error)
|
54
|
+
reflex.broadcast_message subject: "error", body: body, data: data, error: invoke_error
|
55
|
+
else
|
56
|
+
puts "\e[31m#{body}\e[0m"
|
57
|
+
end
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
if reflex.halted?
|
62
|
+
reflex.broadcast_message subject: "halted", data: data
|
63
|
+
else
|
64
|
+
begin
|
65
|
+
reflex.broadcast(selectors, data)
|
66
|
+
rescue => render_error
|
67
|
+
reflex.rescue_with_handler(render_error)
|
68
|
+
message = exception_message_with_backtrace(render_error)
|
69
|
+
body = "Reflex failed to re-render: #{message} [#{url}]"
|
70
|
+
reflex.broadcast_message subject: "error", body: body, data: data, error: render_error
|
71
|
+
puts "\e[31m#{body}\e[0m"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
ensure
|
75
|
+
if reflex
|
76
|
+
commit_session(reflex)
|
77
|
+
reflex.logger.print
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def object_with_indifferent_access(object)
|
85
|
+
return object.with_indifferent_access if object.respond_to?(:with_indifferent_access)
|
86
|
+
object.map! { |obj| object_with_indifferent_access obj } if object.is_a?(Array)
|
87
|
+
object
|
88
|
+
end
|
89
|
+
|
90
|
+
def is_reflex?(reflex_class)
|
91
|
+
reflex_class.ancestors.include? StimulusReflex::Reflex
|
92
|
+
end
|
93
|
+
|
94
|
+
def delegate_call_to_reflex(reflex, method_name, arguments = [])
|
95
|
+
method = reflex.method(method_name)
|
96
|
+
required_params = method.parameters.select { |(kind, _)| kind == :req }
|
97
|
+
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
98
|
+
|
99
|
+
if arguments.size == 0 && required_params.size == 0
|
100
|
+
reflex.process(method_name)
|
101
|
+
elsif arguments.size >= required_params.size && arguments.size <= required_params.size + optional_params.size
|
102
|
+
reflex.process(method_name, *arguments)
|
103
|
+
else
|
104
|
+
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def commit_session(reflex)
|
109
|
+
store = reflex.request.session.instance_variable_get("@by")
|
110
|
+
store.commit_session reflex.request, reflex.controller.response
|
111
|
+
rescue => e
|
112
|
+
message = "Failed to commit session! #{exception_message_with_backtrace(e)}"
|
113
|
+
puts "\e[31m#{message}\e[0m"
|
114
|
+
end
|
115
|
+
|
116
|
+
def exception_message_with_backtrace(exception)
|
117
|
+
"#{exception}\n#{exception.backtrace.first}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def fix_environment!
|
121
|
+
([ApplicationController] + ApplicationController.descendants).each do |controller|
|
122
|
+
controller.renderer.instance_variable_set(:@env, connection.env.merge(controller.renderer.instance_variable_get(:@env)))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/bin/standardize
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
StimulusReflex.configure do |config|
|
4
|
-
# Enable/disable
|
5
|
-
#
|
4
|
+
# Enable/disable exiting / warning when the sanity checks fail options:
|
5
|
+
# `:exit` or `:warn` or `:ignore`
|
6
|
+
|
7
|
+
# config.on_failed_sanity_checks = :exit
|
6
8
|
|
7
9
|
# Override the parent class that the StimulusReflex ActionCable channel inherits from
|
10
|
+
|
8
11
|
# config.parent_channel = "ApplicationCable::Channel"
|
12
|
+
|
13
|
+
# Customize server-side Reflex logging format, with optional colorization:
|
14
|
+
# Available tokens: session_id, session_id_full, reflex_info, operation, reflex_id, reflex_id_full, mode, selector, operation_counter, connection_id, connection_id_full, timestamp
|
15
|
+
# Available colors: green, yellow, blue, magenta, cyan, white
|
16
|
+
# You can also use attributes from your ActionCable Connection's identifiers that resolve to valid ActiveRecord models
|
17
|
+
# eg. if your connection is `identified_by :current_user` and your User model has an email attribute, you can access r.email (it will display `-` if the user isn't logged in)
|
18
|
+
|
19
|
+
# config.logging = proc { "[#{session_id}] #{operation_counter.magenta} #{reflex_info.green} -> #{selector.cyan} via #{mode} Morph (#{operation.yellow})" }
|
9
20
|
end
|
data/lib/stimulus_reflex.rb
CHANGED
@@ -17,6 +17,8 @@ require "stimulus_reflex/broadcasters/broadcaster"
|
|
17
17
|
require "stimulus_reflex/broadcasters/nothing_broadcaster"
|
18
18
|
require "stimulus_reflex/broadcasters/page_broadcaster"
|
19
19
|
require "stimulus_reflex/broadcasters/selector_broadcaster"
|
20
|
+
require "stimulus_reflex/utils/colorize"
|
21
|
+
require "stimulus_reflex/logger"
|
20
22
|
|
21
23
|
module StimulusReflex
|
22
24
|
class Engine < Rails::Engine
|
@@ -4,12 +4,13 @@ module StimulusReflex
|
|
4
4
|
class Broadcaster
|
5
5
|
include CableReady::Broadcaster
|
6
6
|
|
7
|
-
attr_reader :reflex, :logger
|
7
|
+
attr_reader :reflex, :logger, :operations
|
8
8
|
delegate :permanent_attribute_name, :stream_name, to: :reflex
|
9
9
|
|
10
10
|
def initialize(reflex)
|
11
11
|
@reflex = reflex
|
12
|
-
@logger = Rails.logger
|
12
|
+
@logger = Rails.logger if defined?(Rails.logger)
|
13
|
+
@operations = []
|
13
14
|
end
|
14
15
|
|
15
16
|
def nothing?
|
@@ -26,6 +27,7 @@ module StimulusReflex
|
|
26
27
|
|
27
28
|
def broadcast_message(subject:, body: nil, data: {}, error: nil)
|
28
29
|
logger.error "\e[31m#{body}\e[0m" if subject == "error"
|
30
|
+
operations << ["document", :dispatch_event]
|
29
31
|
cable_ready[stream_name].dispatch_event(
|
30
32
|
name: "stimulus-reflex:server-message",
|
31
33
|
detail: {
|
@@ -48,5 +50,10 @@ module StimulusReflex
|
|
48
50
|
def to_sym
|
49
51
|
raise NotImplementedError
|
50
52
|
end
|
53
|
+
|
54
|
+
# abstract method to be implemented by subclasses
|
55
|
+
def to_s
|
56
|
+
raise NotImplementedError
|
57
|
+
end
|
51
58
|
end
|
52
59
|
end
|