stimulus_reflex 3.3.0.pre1 → 3.3.0.pre2
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 +22 -3
- data/Gemfile.lock +3 -3
- data/README.md +1 -1
- data/lib/stimulus_reflex.rb +4 -5
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +55 -0
- data/lib/stimulus_reflex/{morph_mode/nothing_morph_mode.rb → broadcasters/nothing_broadcaster.rb} +8 -6
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +37 -0
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +54 -0
- data/lib/stimulus_reflex/channel.rb +4 -7
- data/lib/stimulus_reflex/reflex.rb +11 -28
- data/lib/stimulus_reflex/version.rb +1 -1
- data/tags +51 -17
- metadata +6 -7
- data/lib/stimulus_reflex/broadcaster.rb +0 -53
- data/lib/stimulus_reflex/morph_mode.rb +0 -19
- data/lib/stimulus_reflex/morph_mode/page_morph_mode.rb +0 -15
- data/lib/stimulus_reflex/morph_mode/selector_morph_mode.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16b54837068db127425aef4bb7d055fb461ed06cfd1693a1303f4b2e7c8e94d2
|
4
|
+
data.tar.gz: 23cb0849034978ecae65551b069f0173d9a63fd78db7233b11e4453be752cb48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f1f347aad5757ee0f2420f4d781626f759f2bd00ed8392f101d52fd813e1e6e1ae9cbfde1fa3954332ad55766569cb1bcf33a56d1dc26b952057e60f97ad7b
|
7
|
+
data.tar.gz: eadb6be440d20ab3183e373e07579fbd7462d2b2fab06c60a80a0d9991c7003f10674e6696eb34e30e320e359b544bc8d25b9c0252bb251cb0d8a32f5946d766
|
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,30 @@
|
|
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.
|
5
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.3.0.pre1...HEAD)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- afterReflex not always firing on morph with selectors [\#269](https://github.com/hopsoft/stimulus_reflex/issues/269)
|
10
|
+
- Lifecycle hooks [\#266](https://github.com/hopsoft/stimulus_reflex/issues/266)
|
11
|
+
- Stimulus Reflex with Rspec not working [\#263](https://github.com/hopsoft/stimulus_reflex/issues/263)
|
12
|
+
|
13
|
+
**Merged pull requests:**
|
14
|
+
|
15
|
+
- Smarter warnings when element not found [\#274](https://github.com/hopsoft/stimulus_reflex/pull/274) ([hopsoft](https://github.com/hopsoft))
|
16
|
+
- Add the attributes to the warning message when element not found [\#273](https://github.com/hopsoft/stimulus_reflex/pull/273) ([hopsoft](https://github.com/hopsoft))
|
17
|
+
- Update find element to ignore SR attrs [\#272](https://github.com/hopsoft/stimulus_reflex/pull/272) ([hopsoft](https://github.com/hopsoft))
|
18
|
+
- Refactor of the morph feature [\#270](https://github.com/hopsoft/stimulus_reflex/pull/270) ([hopsoft](https://github.com/hopsoft))
|
19
|
+
- coerce html arguments to string type [\#268](https://github.com/hopsoft/stimulus_reflex/pull/268) ([leastbad](https://github.com/leastbad))
|
20
|
+
- Update deployment docs after the official AnyCable 1.0 release [\#267](https://github.com/hopsoft/stimulus_reflex/pull/267) ([rmacklin](https://github.com/rmacklin))
|
21
|
+
|
22
|
+
## [v3.3.0.pre1](https://github.com/hopsoft/stimulus_reflex/tree/v3.3.0.pre1) (2020-07-08)
|
23
|
+
|
24
|
+
[Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.3.0.pre0...v3.3.0.pre1)
|
6
25
|
|
7
26
|
**Merged pull requests:**
|
8
27
|
|
9
|
-
-
|
28
|
+
- Fix selector morphs for updating partials and ViewComponents [\#262](https://github.com/hopsoft/stimulus_reflex/pull/262) ([leastbad](https://github.com/leastbad))
|
10
29
|
|
11
30
|
## [v3.3.0.pre0](https://github.com/hopsoft/stimulus_reflex/tree/v3.3.0.pre0) (2020-07-04)
|
12
31
|
|
@@ -181,6 +200,7 @@
|
|
181
200
|
- Some housekeeping [\#189](https://github.com/hopsoft/stimulus_reflex/pull/189) ([hopsoft](https://github.com/hopsoft))
|
182
201
|
- Allow to call stimulate without a reflex target [\#188](https://github.com/hopsoft/stimulus_reflex/pull/188) ([marcoroth](https://github.com/marcoroth))
|
183
202
|
- Fix bug in super documentation [\#174](https://github.com/hopsoft/stimulus_reflex/pull/174) ([silva96](https://github.com/silva96))
|
203
|
+
- Support devise authenticated routes [\#172](https://github.com/hopsoft/stimulus_reflex/pull/172) ([db0sch](https://github.com/db0sch))
|
184
204
|
|
185
205
|
## [v3.1.4](https://github.com/hopsoft/stimulus_reflex/tree/v3.1.4) (2020-04-27)
|
186
206
|
|
@@ -208,7 +228,6 @@
|
|
208
228
|
|
209
229
|
- prettier-standard: include all js files in the project [\#177](https://github.com/hopsoft/stimulus_reflex/pull/177) ([marcoroth](https://github.com/marcoroth))
|
210
230
|
- Remove implicit permanent for text inputs [\#176](https://github.com/hopsoft/stimulus_reflex/pull/176) ([hopsoft](https://github.com/hopsoft))
|
211
|
-
- Support devise authenticated routes [\#172](https://github.com/hopsoft/stimulus_reflex/pull/172) ([db0sch](https://github.com/db0sch))
|
212
231
|
- setupDeclarativeReflexes export with UJS support [\#169](https://github.com/hopsoft/stimulus_reflex/pull/169) ([leastbad](https://github.com/leastbad))
|
213
232
|
- Fix compilation issue [\#168](https://github.com/hopsoft/stimulus_reflex/pull/168) ([jonathan-s](https://github.com/jonathan-s))
|
214
233
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (3.3.0.
|
4
|
+
stimulus_reflex (3.3.0.pre2)
|
5
5
|
cable_ready (>= 4.1.2)
|
6
6
|
nokogiri
|
7
7
|
rack
|
@@ -164,10 +164,10 @@ GEM
|
|
164
164
|
tzinfo (1.2.7)
|
165
165
|
thread_safe (~> 0.1)
|
166
166
|
unicode-display_width (1.7.0)
|
167
|
-
websocket-driver (0.7.
|
167
|
+
websocket-driver (0.7.3)
|
168
168
|
websocket-extensions (>= 0.1.0)
|
169
169
|
websocket-extensions (0.1.5)
|
170
|
-
zeitwerk (2.
|
170
|
+
zeitwerk (2.4.0)
|
171
171
|
|
172
172
|
PLATFORMS
|
173
173
|
ruby
|
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-1098-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" />
|
data/lib/stimulus_reflex.rb
CHANGED
@@ -11,12 +11,11 @@ require "cable_ready"
|
|
11
11
|
require "stimulus_reflex/version"
|
12
12
|
require "stimulus_reflex/reflex"
|
13
13
|
require "stimulus_reflex/element"
|
14
|
-
require "stimulus_reflex/broadcaster"
|
15
|
-
require "stimulus_reflex/morph_mode"
|
16
14
|
require "stimulus_reflex/channel"
|
17
|
-
require "stimulus_reflex/
|
18
|
-
require "stimulus_reflex/
|
19
|
-
require "stimulus_reflex/
|
15
|
+
require "stimulus_reflex/broadcasters/broadcaster"
|
16
|
+
require "stimulus_reflex/broadcasters/nothing_broadcaster"
|
17
|
+
require "stimulus_reflex/broadcasters/page_broadcaster"
|
18
|
+
require "stimulus_reflex/broadcasters/selector_broadcaster"
|
20
19
|
require "generators/stimulus_reflex_generator"
|
21
20
|
|
22
21
|
module StimulusReflex
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StimulusReflex
|
4
|
+
class Broadcaster
|
5
|
+
include CableReady::Broadcaster
|
6
|
+
|
7
|
+
attr_reader :reflex, :logger
|
8
|
+
delegate :permanent_attribute_name, :stream_name, to: :reflex
|
9
|
+
|
10
|
+
def initialize(reflex)
|
11
|
+
@reflex = reflex
|
12
|
+
@logger = Rails.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def nothing?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def page?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def selector?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def enqueue_message(subject:, body: nil, data: {})
|
28
|
+
logger.error "\e[31m#{body}\e[0m" if subject == "error"
|
29
|
+
cable_ready[stream_name].dispatch_event(
|
30
|
+
name: "stimulus-reflex:server-message",
|
31
|
+
detail: {
|
32
|
+
stimulus_reflex: data.merge(
|
33
|
+
broadcaster: to_sym,
|
34
|
+
server_message: {subject: subject, body: body}
|
35
|
+
)
|
36
|
+
}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def broadcast_message(subject:, body: nil, data: {})
|
41
|
+
enqueue_message subject: subject, body: body, data: data
|
42
|
+
cable_ready.broadcast
|
43
|
+
end
|
44
|
+
|
45
|
+
# abstract method to be implemented by subclasses
|
46
|
+
def broadcast(*args)
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
49
|
+
|
50
|
+
# abstract method to be implemented by subclasses
|
51
|
+
def to_sym
|
52
|
+
raise NotImplementedError
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/stimulus_reflex/{morph_mode/nothing_morph_mode.rb → broadcasters/nothing_broadcaster.rb}
RENAMED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module StimulusReflex
|
2
|
-
class
|
3
|
-
def broadcast(
|
4
|
+
class NothingBroadcaster < Broadcaster
|
5
|
+
def broadcast(_, data)
|
4
6
|
broadcast_message subject: "nothing", data: data
|
5
7
|
end
|
6
8
|
|
7
|
-
def to_sym
|
8
|
-
:nothing
|
9
|
-
end
|
10
|
-
|
11
9
|
def nothing?
|
12
10
|
true
|
13
11
|
end
|
12
|
+
|
13
|
+
def to_sym
|
14
|
+
:nothing
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StimulusReflex
|
4
|
+
class PageBroadcaster < Broadcaster
|
5
|
+
def broadcast(selectors, data)
|
6
|
+
reflex.controller.process reflex.url_params[:action]
|
7
|
+
page_html = reflex.controller.response.body
|
8
|
+
|
9
|
+
return unless page_html.present?
|
10
|
+
|
11
|
+
document = Nokogiri::HTML(page_html)
|
12
|
+
selectors = selectors.select { |s| document.css(s).present? }
|
13
|
+
selectors.each do |selector|
|
14
|
+
html = document.css(selector).inner_html
|
15
|
+
cable_ready[stream_name].morph(
|
16
|
+
selector: selector,
|
17
|
+
html: html,
|
18
|
+
children_only: true,
|
19
|
+
permanent_attribute_name: permanent_attribute_name,
|
20
|
+
stimulus_reflex: data.merge({
|
21
|
+
last: selector == selectors.last,
|
22
|
+
broadast_type: to_sym
|
23
|
+
})
|
24
|
+
)
|
25
|
+
end
|
26
|
+
cable_ready.broadcast
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_sym
|
30
|
+
:page
|
31
|
+
end
|
32
|
+
|
33
|
+
def page?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StimulusReflex
|
4
|
+
class SelectorBroadcaster < Broadcaster
|
5
|
+
def broadcast(_, data = {})
|
6
|
+
morphs.each do |morph|
|
7
|
+
selectors, html = morph
|
8
|
+
updates = selectors.is_a?(Hash) ? selectors : Hash[selectors, html]
|
9
|
+
updates.each do |selector, html|
|
10
|
+
last = morph == morphs.last && selector == updates.keys.last
|
11
|
+
html = html.to_s
|
12
|
+
fragment = Nokogiri::HTML.fragment(html)
|
13
|
+
match = fragment.at_css(selector)
|
14
|
+
if match.present?
|
15
|
+
cable_ready[stream_name].morph(
|
16
|
+
selector: selector,
|
17
|
+
html: match.inner_html,
|
18
|
+
children_only: true,
|
19
|
+
permanent_attribute_name: permanent_attribute_name,
|
20
|
+
stimulus_reflex: data.merge({
|
21
|
+
last: last,
|
22
|
+
broadast_type: to_sym
|
23
|
+
})
|
24
|
+
)
|
25
|
+
else
|
26
|
+
cable_ready[stream_name].inner_html(
|
27
|
+
selector: selector,
|
28
|
+
html: fragment.to_html,
|
29
|
+
stimulus_reflex: data.merge({
|
30
|
+
last: last,
|
31
|
+
broadast_type: to_sym
|
32
|
+
})
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
cable_ready.broadcast
|
39
|
+
morphs.clear
|
40
|
+
end
|
41
|
+
|
42
|
+
def morphs
|
43
|
+
@morphs ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_sym
|
47
|
+
:selector
|
48
|
+
end
|
49
|
+
|
50
|
+
def selector?
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class StimulusReflex::Channel < ActionCable::Channel::Base
|
4
|
-
include StimulusReflex::Broadcaster
|
5
|
-
|
6
4
|
def stream_name
|
7
5
|
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
8
6
|
[
|
@@ -36,19 +34,18 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
|
|
36
34
|
rescue => invoke_error
|
37
35
|
reflex&.rescue_with_handler(invoke_error)
|
38
36
|
message = exception_message_with_backtrace(invoke_error)
|
39
|
-
return broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data: data
|
37
|
+
return reflex.broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}", data: data
|
40
38
|
end
|
41
39
|
|
42
40
|
if reflex.halted?
|
43
|
-
broadcast_message subject: "halted", data: data
|
41
|
+
reflex.broadcast_message subject: "halted", data: data
|
44
42
|
else
|
45
43
|
begin
|
46
|
-
reflex.
|
47
|
-
reflex.morph_mode.broadcast(reflex, selectors, data)
|
44
|
+
reflex.broadcast(selectors, data)
|
48
45
|
rescue => render_error
|
49
46
|
reflex.rescue_with_handler(render_error)
|
50
47
|
message = exception_message_with_backtrace(render_error)
|
51
|
-
broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to re-render #{url} #{message}", data: data
|
48
|
+
reflex.broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to re-render #{url} #{message}", data: data
|
52
49
|
end
|
53
50
|
end
|
54
51
|
ensure
|
@@ -43,12 +43,13 @@ class StimulusReflex::Reflex
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
attr_reader :channel, :url, :element, :selectors, :method_name, :
|
46
|
+
attr_reader :channel, :url, :element, :selectors, :method_name, :broadcaster, :permanent_attribute_name
|
47
47
|
|
48
|
-
delegate :connection, to: :channel
|
48
|
+
delegate :connection, :stream_name, to: :channel
|
49
49
|
delegate :session, to: :request
|
50
|
+
delegate :broadcast, :broadcast_message, to: :broadcaster
|
50
51
|
|
51
|
-
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil,
|
52
|
+
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, permanent_attribute_name: nil, params: {})
|
52
53
|
@channel = channel
|
53
54
|
@url = url
|
54
55
|
@element = element
|
@@ -56,7 +57,7 @@ class StimulusReflex::Reflex
|
|
56
57
|
@method_name = method_name
|
57
58
|
@params = params
|
58
59
|
@permanent_attribute_name = permanent_attribute_name
|
59
|
-
@
|
60
|
+
@broadcaster = StimulusReflex::PageBroadcaster.new(self)
|
60
61
|
self.params
|
61
62
|
end
|
62
63
|
|
@@ -89,35 +90,17 @@ class StimulusReflex::Reflex
|
|
89
90
|
def morph(selectors, html = "")
|
90
91
|
case selectors
|
91
92
|
when :page
|
92
|
-
raise StandardError.new("Cannot call :page morph after :#{
|
93
|
+
raise StandardError.new("Cannot call :page morph after :#{broadcaster.to_sym} morph") unless broadcaster.page?
|
93
94
|
when :nothing
|
94
|
-
raise StandardError.new("Cannot call :nothing morph after :selector morph") if
|
95
|
-
@
|
95
|
+
raise StandardError.new("Cannot call :nothing morph after :selector morph") if broadcaster.selector?
|
96
|
+
@broadcaster = StimulusReflex::NothingBroadcaster.new(self) unless broadcaster.nothing?
|
96
97
|
else
|
97
|
-
raise StandardError.new("Cannot call :selector morph after :nothing morph") if
|
98
|
-
@
|
99
|
-
|
100
|
-
selectors.each do |selector, html|
|
101
|
-
enqueue_selector_broadcast selector, html
|
102
|
-
end
|
103
|
-
else
|
104
|
-
enqueue_selector_broadcast selectors, html
|
105
|
-
end
|
106
|
-
cable_ready.broadcast
|
98
|
+
raise StandardError.new("Cannot call :selector morph after :nothing morph") if broadcaster.nothing?
|
99
|
+
@broadcaster = StimulusReflex::SelectorBroadcaster.new(self) unless broadcaster.selector?
|
100
|
+
broadcaster.morphs << [selectors, html]
|
107
101
|
end
|
108
102
|
end
|
109
103
|
|
110
|
-
def enqueue_selector_broadcast(selector, html)
|
111
|
-
fragment = Nokogiri::HTML(html)
|
112
|
-
parent = fragment.at_css(selector)
|
113
|
-
cable_ready[channel.stream_name].morph(
|
114
|
-
selector: selector,
|
115
|
-
html: parent.present? ? parent.inner_html : fragment.to_html,
|
116
|
-
children_only: true,
|
117
|
-
permanent_attribute_name: permanent_attribute_name
|
118
|
-
)
|
119
|
-
end
|
120
|
-
|
121
104
|
def controller
|
122
105
|
@controller ||= begin
|
123
106
|
request.controller_class.new.tap do |c|
|
data/tags
CHANGED
@@ -4,39 +4,73 @@
|
|
4
4
|
!_TAG_PROGRAM_NAME Exuberant Ctags //
|
5
5
|
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
6
6
|
!_TAG_PROGRAM_VERSION 5.8 //
|
7
|
-
ApplicationReflex lib/generators/templates/application_reflex.rb /^class ApplicationReflex < StimulusReflex::Reflex$/;" c
|
8
7
|
ApplicationReflex test/tmp/app/reflexes/application_reflex.rb /^class ApplicationReflex < StimulusReflex::Reflex$/;" c
|
8
|
+
Broadcaster lib/stimulus_reflex/broadcasters/broadcaster.rb /^ class Broadcaster$/;" c class:StimulusReflex
|
9
9
|
DemoReflex test/tmp/app/reflexes/demo_reflex.rb /^class DemoReflex < ApplicationReflex$/;" c
|
10
10
|
Engine lib/stimulus_reflex.rb /^ class Engine < Rails::Engine$/;" c class:StimulusReflex
|
11
|
+
NothingBroadcaster lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ class NothingBroadcaster < Broadcaster$/;" c class:StimulusReflex
|
12
|
+
PageBroadcaster lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ class PageBroadcaster < Broadcaster$/;" c class:StimulusReflex
|
13
|
+
SelectorBroadcaster lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ class SelectorBroadcaster < Broadcaster$/;" c class:StimulusReflex
|
11
14
|
StimulusReflex lib/stimulus_reflex.rb /^module StimulusReflex$/;" m
|
15
|
+
StimulusReflex lib/stimulus_reflex/broadcasters/broadcaster.rb /^module StimulusReflex$/;" m
|
16
|
+
StimulusReflex lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^module StimulusReflex$/;" m
|
17
|
+
StimulusReflex lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^module StimulusReflex$/;" m
|
18
|
+
StimulusReflex lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^module StimulusReflex$/;" m
|
12
19
|
StimulusReflex lib/stimulus_reflex/channel.rb /^class StimulusReflex::Channel < ActionCable::Channel::Base$/;" c
|
13
|
-
StimulusReflex lib/stimulus_reflex/element.rb /^class StimulusReflex::Element$/;" c
|
20
|
+
StimulusReflex lib/stimulus_reflex/element.rb /^class StimulusReflex::Element < OpenStruct$/;" c
|
14
21
|
StimulusReflex lib/stimulus_reflex/reflex.rb /^class StimulusReflex::Reflex$/;" c
|
15
22
|
StimulusReflex lib/stimulus_reflex/version.rb /^module StimulusReflex$/;" m
|
16
23
|
StimulusReflexGenerator lib/generators/stimulus_reflex_generator.rb /^class StimulusReflexGenerator < Rails::Generators::NamedBase$/;" c
|
17
24
|
StimulusReflexGeneratorTest test/generators/stimulus_reflex_generator_test.rb /^class StimulusReflexGeneratorTest < Rails::Generators::TestCase$/;" c
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
add_callback lib/stimulus_reflex/reflex.rb /^ def add_callback(kind, *args, &block)$/;" f class:StimulusReflex
|
26
|
+
after_reflex lib/stimulus_reflex/reflex.rb /^ def after_reflex(*args, &block)$/;" f class:StimulusReflex
|
27
|
+
around_reflex lib/stimulus_reflex/reflex.rb /^ def around_reflex(*args, &block)$/;" f class:StimulusReflex
|
28
|
+
before_reflex lib/stimulus_reflex/reflex.rb /^ def before_reflex(*args, &block)$/;" f class:StimulusReflex
|
29
|
+
broadcast lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def broadcast(*args)$/;" f class:StimulusReflex.Broadcaster
|
30
|
+
broadcast lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def broadcast(_, data)$/;" f class:StimulusReflex.NothingBroadcaster
|
31
|
+
broadcast lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def broadcast(selectors, data)$/;" f class:StimulusReflex.PageBroadcaster
|
32
|
+
broadcast lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def broadcast(_, data = {})$/;" f class:StimulusReflex.SelectorBroadcaster
|
33
|
+
broadcast_message lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def broadcast_message(subject:, body: nil, data: {})$/;" f class:StimulusReflex.Broadcaster
|
34
|
+
commit_session lib/stimulus_reflex/channel.rb /^ def commit_session(reflex)$/;" f class:StimulusReflex
|
35
|
+
controller lib/stimulus_reflex/reflex.rb /^ def controller$/;" f
|
36
|
+
copy_application_files lib/generators/stimulus_reflex_generator.rb /^ def copy_application_files$/;" f class:StimulusReflexGenerator
|
24
37
|
dataset lib/stimulus_reflex/element.rb /^ def dataset$/;" f class:StimulusReflex
|
38
|
+
default_reflex lib/stimulus_reflex/reflex.rb /^ def default_reflex$/;" f
|
25
39
|
delegate_call_to_reflex lib/stimulus_reflex/channel.rb /^ def delegate_call_to_reflex(reflex, method_name, arguments = [])$/;" f class:StimulusReflex
|
40
|
+
enqueue_message lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def enqueue_message(subject:, body: nil, data: {})$/;" f class:StimulusReflex.Broadcaster
|
41
|
+
error javascript/log.js /^function error (response) {$/;" f
|
26
42
|
exception_message_with_backtrace lib/stimulus_reflex/channel.rb /^ def exception_message_with_backtrace(exception)$/;" f class:StimulusReflex
|
43
|
+
execute lib/generators/stimulus_reflex_generator.rb /^ def execute$/;" f class:StimulusReflexGenerator
|
27
44
|
export.reflexAttribute javascript/schema.js /^ reflexAttribute: 'data-reflex',$/;" p
|
45
|
+
export.reflexDatasetAttribute javascript/schema.js /^ reflexDatasetAttribute: 'data-reflex-dataset'$/;" p
|
28
46
|
export.reflexPermanentAttribute javascript/schema.js /^ reflexPermanentAttribute: 'data-reflex-permanent',$/;" p
|
29
|
-
export.reflexRootAttribute javascript/schema.js /^ reflexRootAttribute: 'data-reflex-root'
|
47
|
+
export.reflexRootAttribute javascript/schema.js /^ reflexRootAttribute: 'data-reflex-root',$/;" p
|
30
48
|
findConsumer javascript/consumer.js /^function findConsumer (object, depth = 0) {$/;" f
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
49
|
+
function.success javascript/log.js /^function success (response, options = { halted: false }) {$/;" f
|
50
|
+
halted? lib/stimulus_reflex/reflex.rb /^ def halted?$/;" f
|
51
|
+
initialize lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def initialize(reflex)$/;" f class:StimulusReflex.Broadcaster
|
52
|
+
initialize lib/stimulus_reflex/element.rb /^ def initialize(data = {})$/;" f class:StimulusReflex
|
53
|
+
initialize lib/stimulus_reflex/reflex.rb /^ def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, permanent_attribute_name: nil, params: {})$/;" f
|
35
54
|
is_reflex? lib/stimulus_reflex/channel.rb /^ def is_reflex?(reflex_class)$/;" f class:StimulusReflex
|
55
|
+
morph lib/stimulus_reflex/reflex.rb /^ def morph(selectors, html = "")$/;" f
|
56
|
+
morphs lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def morphs$/;" f class:StimulusReflex.SelectorBroadcaster
|
57
|
+
normalize_callback_option! lib/stimulus_reflex/reflex.rb /^ def normalize_callback_option!(options, from, to)$/;" f class:StimulusReflex
|
58
|
+
normalize_callback_options! lib/stimulus_reflex/reflex.rb /^ def normalize_callback_options!(options)$/;" f class:StimulusReflex
|
59
|
+
nothing? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def nothing?$/;" f class:StimulusReflex.Broadcaster
|
60
|
+
nothing? lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def nothing?$/;" f class:StimulusReflex.NothingBroadcaster
|
61
|
+
object_with_indifferent_access lib/stimulus_reflex/channel.rb /^ def object_with_indifferent_access(object)$/;" f class:StimulusReflex
|
62
|
+
page? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def page?$/;" f class:StimulusReflex.Broadcaster
|
63
|
+
page? lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def page?$/;" f class:StimulusReflex.PageBroadcaster
|
64
|
+
params lib/stimulus_reflex/reflex.rb /^ def params$/;" f
|
65
|
+
process lib/stimulus_reflex/reflex.rb /^ def process(name, *args)$/;" f
|
36
66
|
receive lib/stimulus_reflex/channel.rb /^ def receive(data)$/;" f class:StimulusReflex
|
37
|
-
|
38
|
-
|
39
|
-
|
67
|
+
request lib/stimulus_reflex/reflex.rb /^ def request$/;" f
|
68
|
+
selector? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def selector?$/;" f class:StimulusReflex.Broadcaster
|
69
|
+
selector? lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def selector?$/;" f class:StimulusReflex.SelectorBroadcaster
|
40
70
|
stream_name lib/stimulus_reflex/channel.rb /^ def stream_name$/;" f class:StimulusReflex
|
41
71
|
subscribed lib/stimulus_reflex/channel.rb /^ def subscribed$/;" f class:StimulusReflex
|
42
|
-
|
72
|
+
to_sym lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.Broadcaster
|
73
|
+
to_sym lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.NothingBroadcaster
|
74
|
+
to_sym lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.PageBroadcaster
|
75
|
+
to_sym lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.SelectorBroadcaster
|
76
|
+
url_params lib/stimulus_reflex/reflex.rb /^ def url_params$/;" f
|
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.
|
4
|
+
version: 3.3.0.pre2
|
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-07-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -162,13 +162,12 @@ files:
|
|
162
162
|
- lib/generators/templates/app/reflexes/%file_name%_reflex.rb.tt
|
163
163
|
- lib/generators/templates/app/reflexes/application_reflex.rb.tt
|
164
164
|
- lib/stimulus_reflex.rb
|
165
|
-
- lib/stimulus_reflex/broadcaster.rb
|
165
|
+
- lib/stimulus_reflex/broadcasters/broadcaster.rb
|
166
|
+
- lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb
|
167
|
+
- lib/stimulus_reflex/broadcasters/page_broadcaster.rb
|
168
|
+
- lib/stimulus_reflex/broadcasters/selector_broadcaster.rb
|
166
169
|
- lib/stimulus_reflex/channel.rb
|
167
170
|
- lib/stimulus_reflex/element.rb
|
168
|
-
- lib/stimulus_reflex/morph_mode.rb
|
169
|
-
- lib/stimulus_reflex/morph_mode/nothing_morph_mode.rb
|
170
|
-
- lib/stimulus_reflex/morph_mode/page_morph_mode.rb
|
171
|
-
- lib/stimulus_reflex/morph_mode/selector_morph_mode.rb
|
172
171
|
- lib/stimulus_reflex/reflex.rb
|
173
172
|
- lib/stimulus_reflex/version.rb
|
174
173
|
- lib/tasks/stimulus_reflex/install.rake
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module StimulusReflex
|
2
|
-
module Broadcaster
|
3
|
-
include CableReady::Broadcaster
|
4
|
-
|
5
|
-
def render_page_and_broadcast_morph(reflex, selectors, data = {})
|
6
|
-
html = render_page(reflex)
|
7
|
-
broadcast_morphs selectors, data, html if html.present?
|
8
|
-
end
|
9
|
-
|
10
|
-
def render_page(reflex)
|
11
|
-
reflex.controller.process reflex.url_params[:action]
|
12
|
-
reflex.controller.response.body
|
13
|
-
end
|
14
|
-
|
15
|
-
def broadcast_morphs(selectors, data, html)
|
16
|
-
document = Nokogiri::HTML(html)
|
17
|
-
selectors = selectors.select { |s| document.css(s).present? }
|
18
|
-
selectors.each do |selector|
|
19
|
-
cable_ready[stream_name].morph(
|
20
|
-
selector: selector,
|
21
|
-
html: document.css(selector).inner_html,
|
22
|
-
children_only: true,
|
23
|
-
permanent_attribute_name: data["permanent_attribute_name"],
|
24
|
-
stimulus_reflex: data.merge({
|
25
|
-
last: selector == selectors.last,
|
26
|
-
morph_mode: "page"
|
27
|
-
})
|
28
|
-
)
|
29
|
-
end
|
30
|
-
cable_ready.broadcast
|
31
|
-
end
|
32
|
-
|
33
|
-
def broadcast_message(subject:, body: nil, data: {})
|
34
|
-
message = {
|
35
|
-
subject: subject,
|
36
|
-
body: body
|
37
|
-
}
|
38
|
-
|
39
|
-
logger.error "\e[31m#{body}\e[0m" if subject == "error"
|
40
|
-
|
41
|
-
data[:morph_mode] = "page"
|
42
|
-
data[:server_message] = message
|
43
|
-
data[:morph_mode] = "selector" if subject == "selector"
|
44
|
-
data[:morph_mode] = "nothing" if subject == "nothing"
|
45
|
-
|
46
|
-
cable_ready[stream_name].dispatch_event(
|
47
|
-
name: "stimulus-reflex:server-message",
|
48
|
-
detail: {stimulus_reflex: data}
|
49
|
-
)
|
50
|
-
cable_ready.broadcast
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|