stimulus_reflex 3.3.0 → 3.4.0.pre0
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 +55 -8
- data/Gemfile.lock +66 -65
- data/README.md +5 -2
- data/lib/generators/stimulus_reflex/config_generator.rb +14 -0
- data/lib/generators/{stimulus_reflex_generator.rb → stimulus_reflex/stimulus_reflex_generator.rb} +0 -0
- data/lib/generators/{templates → stimulus_reflex/templates}/app/javascript/controllers/%file_name%_controller.js.tt +0 -0
- data/lib/generators/{templates → stimulus_reflex/templates}/app/javascript/controllers/application_controller.js.tt +0 -0
- data/lib/generators/{templates → stimulus_reflex/templates}/app/reflexes/%file_name%_reflex.rb.tt +0 -0
- data/lib/generators/{templates → stimulus_reflex/templates}/app/reflexes/application_reflex.rb.tt +0 -0
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +9 -0
- data/lib/stimulus_reflex.rb +1 -2
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +3 -7
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +2 -2
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +2 -2
- data/lib/stimulus_reflex/configuration.rb +24 -0
- data/lib/stimulus_reflex/element.rb +8 -0
- data/lib/stimulus_reflex/reflex.rb +21 -18
- data/lib/stimulus_reflex/sanity_checker.rb +36 -18
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/tasks/stimulus_reflex/install.rake +11 -8
- data/package.json +63 -0
- data/stimulus_reflex.gemspec +40 -0
- data/tags +98 -0
- data/test/generators/stimulus_reflex_generator_test.rb +1 -0
- data/test/tmp/app/reflexes/application_reflex.rb +12 -0
- data/test/tmp/app/reflexes/user_reflex.rb +33 -0
- data/yarn.lock +6261 -0
- metadata +25 -15
- data/lib/stimulus_reflex/channel.rb +0 -110
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.
|
4
|
+
version: 3.4.0.pre0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description:
|
153
|
+
description:
|
154
154
|
email:
|
155
155
|
- natehop@gmail.com
|
156
156
|
executables: []
|
@@ -170,24 +170,32 @@ files:
|
|
170
170
|
- bin/setup
|
171
171
|
- bin/standardize
|
172
172
|
- lib/generators/USAGE
|
173
|
-
- lib/generators/
|
174
|
-
- lib/generators/
|
175
|
-
- lib/generators/templates/app/javascript/controllers
|
176
|
-
- lib/generators/templates/app/
|
177
|
-
- lib/generators/templates/app/reflexes
|
173
|
+
- lib/generators/stimulus_reflex/config_generator.rb
|
174
|
+
- lib/generators/stimulus_reflex/stimulus_reflex_generator.rb
|
175
|
+
- lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt
|
176
|
+
- lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt
|
177
|
+
- lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt
|
178
|
+
- lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt
|
179
|
+
- lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb
|
178
180
|
- lib/stimulus_reflex.rb
|
179
181
|
- lib/stimulus_reflex/broadcasters/broadcaster.rb
|
180
182
|
- lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb
|
181
183
|
- lib/stimulus_reflex/broadcasters/page_broadcaster.rb
|
182
184
|
- lib/stimulus_reflex/broadcasters/selector_broadcaster.rb
|
183
|
-
- lib/stimulus_reflex/
|
185
|
+
- lib/stimulus_reflex/configuration.rb
|
184
186
|
- lib/stimulus_reflex/element.rb
|
185
187
|
- lib/stimulus_reflex/reflex.rb
|
186
188
|
- lib/stimulus_reflex/sanity_checker.rb
|
187
189
|
- lib/stimulus_reflex/version.rb
|
188
190
|
- lib/tasks/stimulus_reflex/install.rake
|
191
|
+
- package.json
|
192
|
+
- stimulus_reflex.gemspec
|
193
|
+
- tags
|
189
194
|
- test/generators/stimulus_reflex_generator_test.rb
|
190
195
|
- test/test_helper.rb
|
196
|
+
- test/tmp/app/reflexes/application_reflex.rb
|
197
|
+
- test/tmp/app/reflexes/user_reflex.rb
|
198
|
+
- yarn.lock
|
191
199
|
homepage: https://github.com/hopsoft/stimulus_reflex
|
192
200
|
licenses:
|
193
201
|
- MIT
|
@@ -212,14 +220,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
212
220
|
version: '0'
|
213
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
222
|
requirements:
|
215
|
-
- - "
|
223
|
+
- - ">"
|
216
224
|
- !ruby/object:Gem::Version
|
217
|
-
version:
|
225
|
+
version: 1.3.1
|
218
226
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
220
|
-
signing_key:
|
227
|
+
rubygems_version: 3.1.2
|
228
|
+
signing_key:
|
221
229
|
specification_version: 4
|
222
230
|
summary: Build reactive applications with the Rails tooling you already know and love.
|
223
231
|
test_files:
|
224
|
-
- test/generators/stimulus_reflex_generator_test.rb
|
225
232
|
- test/test_helper.rb
|
233
|
+
- test/generators/stimulus_reflex_generator_test.rb
|
234
|
+
- test/tmp/app/reflexes/application_reflex.rb
|
235
|
+
- test/tmp/app/reflexes/user_reflex.rb
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ApplicationCable
|
4
|
-
class Channel < ActionCable::Channel::Base
|
5
|
-
def initialize(connection, identifier, params = {})
|
6
|
-
super
|
7
|
-
application_channel = Rails.root.join("app", "channels", "application_cable", "channel.rb")
|
8
|
-
require application_channel if File.exist?(application_channel)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class StimulusReflex::Channel < ApplicationCable::Channel
|
14
|
-
def stream_name
|
15
|
-
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
16
|
-
[
|
17
|
-
params[:channel],
|
18
|
-
ids.select(&:present?).join(";")
|
19
|
-
].select(&:present?).join(":")
|
20
|
-
end
|
21
|
-
|
22
|
-
def subscribed
|
23
|
-
super
|
24
|
-
stream_from stream_name
|
25
|
-
end
|
26
|
-
|
27
|
-
def receive(data)
|
28
|
-
url = data["url"].to_s
|
29
|
-
selectors = (data["selectors"] || []).select(&:present?)
|
30
|
-
selectors = data["selectors"] = ["body"] if selectors.blank?
|
31
|
-
target = data["target"].to_s
|
32
|
-
reflex_name, method_name = target.split("#")
|
33
|
-
reflex_name = reflex_name.camelize
|
34
|
-
reflex_name = reflex_name.end_with?("Reflex") ? reflex_name : "#{reflex_name}Reflex"
|
35
|
-
arguments = (data["args"] || []).map { |arg| object_with_indifferent_access arg }
|
36
|
-
element = StimulusReflex::Element.new(data)
|
37
|
-
permanent_attribute_name = data["permanent_attribute_name"]
|
38
|
-
params = data["params"] || {}
|
39
|
-
|
40
|
-
begin
|
41
|
-
begin
|
42
|
-
reflex_class = reflex_name.constantize.tap { |klass| raise ArgumentError.new("#{reflex_name} is not a StimulusReflex::Reflex") unless is_reflex?(klass) }
|
43
|
-
reflex = reflex_class.new(self, url: url, element: element, selectors: selectors, method_name: method_name, permanent_attribute_name: permanent_attribute_name, params: params)
|
44
|
-
delegate_call_to_reflex reflex, method_name, arguments
|
45
|
-
rescue => invoke_error
|
46
|
-
message = exception_message_with_backtrace(invoke_error)
|
47
|
-
body = "StimulusReflex::Channel Failed to invoke #{target}! #{url} #{message}"
|
48
|
-
if reflex
|
49
|
-
reflex.rescue_with_handler(invoke_error)
|
50
|
-
reflex.broadcast_message subject: "error", body: body, data: data
|
51
|
-
else
|
52
|
-
logger.error "\e[31m#{body}\e[0m"
|
53
|
-
end
|
54
|
-
return
|
55
|
-
end
|
56
|
-
|
57
|
-
if reflex.halted?
|
58
|
-
reflex.broadcast_message subject: "halted", data: data
|
59
|
-
else
|
60
|
-
begin
|
61
|
-
reflex.broadcast(selectors, data)
|
62
|
-
rescue => render_error
|
63
|
-
reflex.rescue_with_handler(render_error)
|
64
|
-
message = exception_message_with_backtrace(render_error)
|
65
|
-
reflex.broadcast_message subject: "error", body: "StimulusReflex::Channel Failed to re-render #{url} #{message}", data: data
|
66
|
-
end
|
67
|
-
end
|
68
|
-
ensure
|
69
|
-
commit_session reflex if reflex
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def object_with_indifferent_access(object)
|
76
|
-
return object.with_indifferent_access if object.respond_to?(:with_indifferent_access)
|
77
|
-
object.map! { |obj| object_with_indifferent_access obj } if object.is_a?(Array)
|
78
|
-
object
|
79
|
-
end
|
80
|
-
|
81
|
-
def is_reflex?(reflex_class)
|
82
|
-
reflex_class.ancestors.include? StimulusReflex::Reflex
|
83
|
-
end
|
84
|
-
|
85
|
-
def delegate_call_to_reflex(reflex, method_name, arguments = [])
|
86
|
-
method = reflex.method(method_name)
|
87
|
-
required_params = method.parameters.select { |(kind, _)| kind == :req }
|
88
|
-
optional_params = method.parameters.select { |(kind, _)| kind == :opt }
|
89
|
-
|
90
|
-
if arguments.size == 0 && required_params.size == 0
|
91
|
-
reflex.process(method_name)
|
92
|
-
elsif arguments.size >= required_params.size && arguments.size <= required_params.size + optional_params.size
|
93
|
-
reflex.process(method_name, *arguments)
|
94
|
-
else
|
95
|
-
raise ArgumentError.new("wrong number of arguments (given #{arguments.inspect}, expected #{required_params.inspect}, optional #{optional_params.inspect})")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def commit_session(reflex)
|
100
|
-
store = reflex.request.session.instance_variable_get("@by")
|
101
|
-
store.commit_session reflex.request, reflex.controller.response
|
102
|
-
rescue => e
|
103
|
-
message = "Failed to commit session! #{exception_message_with_backtrace(e)}"
|
104
|
-
logger.error "\e[31m#{message}\e[0m"
|
105
|
-
end
|
106
|
-
|
107
|
-
def exception_message_with_backtrace(exception)
|
108
|
-
"#{exception} #{exception.backtrace.first}"
|
109
|
-
end
|
110
|
-
end
|