view_component_reflex 2.1.0 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 415195dd61211d392433d4e85963a6807871143f255b3264e2f7b4871bb42c42
4
- data.tar.gz: 69f6030f02557d4d9886e3cfc00c738c66d748eb7a1a4b8149136ddaef8f8e9d
3
+ metadata.gz: 3cba771f1bff88b05863347a7bd1d071b8c931cdab779b65223b05e103a841d7
4
+ data.tar.gz: 9251cf944ebdc965b26afb5d4e15002a98c230a6efb3dc528f3e88873843f22d
5
5
  SHA512:
6
- metadata.gz: e12ff695c21dc3f6c140c9d7aa7ccc854eeaeacf2a8071dc519f87c4ca1447464c01f8dfc9c200c0ac720dd864a71788fcc80f74072577c4c833743ccea29c79
7
- data.tar.gz: ed7a85c244de733490571e7c4b529ce7b8dd295c0f6c1a5d57b15f40460b4a3737f2669bf8f28845d80a06b2ed721de49bc810c7ac9477629ead664635b2f2ee
6
+ metadata.gz: c35f1bf68654bdb97acb33af4e7552fd3b6fb3f3bbf8cf599b214a35340a8648ed614c6ca4281df19446ce997be4ee493b56e08f3480b10d4d84cab38ccd68fb
7
+ data.tar.gz: 93a5a0702e21814df172fef57d1cadbc4c91c9d8123affb3d331e3fa8cc98e0c6055257f2c8754e86d6a1ef05170c7aa8ad806455ad8610c650f59aa3a4fc417
data/README.md CHANGED
@@ -219,7 +219,7 @@ ViewComponentReflex uses session for its state by default. To change this, add
219
219
  an initializer to `config/initializers/view_component_reflex.rb`.
220
220
 
221
221
  ```ruby
222
- ViewComponentReflex.configure do |config|
222
+ ViewComponentReflex::Engine.configure do |config|
223
223
  config.state_adapter = YourAdapter
224
224
  end
225
225
  ```
@@ -279,9 +279,19 @@ Or install it yourself as:
279
279
  $ gem install view_component_reflex
280
280
  ```
281
281
 
282
+ ## Common problems
283
+
284
+ # Uninitialized constants \<component\>Reflex
285
+ A component needs to be wrapped in `<%= component_controller do %>` in order to properly initialize, otherwise the Reflex class won't get created.
286
+
282
287
  ## License
283
288
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
284
289
 
285
290
  ## Caveats
286
291
 
287
292
  State uses session to maintain state as of right now. It also assumes your component view is written with the file extension `.html.erb`
293
+
294
+ ## Support me
295
+
296
+ <a href="https://www.buymeacoffee.com/jleblanc" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="40" ></a>
297
+
@@ -2,7 +2,11 @@ module ViewComponentReflex
2
2
  class Component < ViewComponent::Base
3
3
  class << self
4
4
  def init_stimulus_reflex
5
- @stimulus_reflex ||= Object.const_set(name + "Reflex", Class.new(Reflex))
5
+ @stimulus_reflex ||= if name.include? "::"
6
+ module_parent.const_set(name.split("::").last + "Reflex", Class.new(Reflex))
7
+ else
8
+ Object.const_set(name + "Reflex", Class.new(Reflex))
9
+ end
6
10
  @stimulus_reflex.component_class = self
7
11
  end
8
12
  end
@@ -20,11 +24,11 @@ module ViewComponentReflex
20
24
  init_key
21
25
 
22
26
  tag = :div
23
- if opts_or_tag.is_a? Hash
24
- options = opts_or_tag
27
+ options = if opts_or_tag.is_a? Hash
28
+ opts_or_tag
25
29
  else
26
30
  tag = opts_or_tag
27
- options = opts
31
+ opts
28
32
  end
29
33
  options[:data] = {
30
34
  controller: self.class.stimulus_controller,
@@ -2,6 +2,7 @@ require "view_component_reflex/state_adapter/session"
2
2
  require "view_component_reflex/state_adapter/memory"
3
3
  require "view_component_reflex/engine"
4
4
  require "stimulus_reflex"
5
+ require "view_component_reflex/reflex"
5
6
 
6
7
  module ViewComponentReflex
7
8
  # Your code goes here...
@@ -61,19 +61,26 @@ module ViewComponentReflex
61
61
  # uses method to gather the method parameters, but since we're abusing
62
62
  # method_missing here, that'll always fail
63
63
  def method(name)
64
- name.to_sym.to_proc
64
+ component.method(name.to_sym)
65
65
  end
66
66
 
67
67
  def respond_to_missing?(name, _ = false)
68
68
  !!name.to_proc
69
69
  end
70
70
 
71
- before_reflex do |a|
72
- a.send a.method_name
73
- throw :abort
71
+ # this is copied out of stimulus_reflex/reflex.rb and modified
72
+ def morph(selectors, html = "")
73
+ case selectors
74
+ when :nothing
75
+ @broadcaster = StimulusReflex::NothingBroadcaster.new(self)
76
+ else
77
+ @broadcaster = StimulusReflex::SelectorBroadcaster.new(self) unless broadcaster.selector?
78
+ broadcaster.morphs << [selectors, html]
79
+ end
74
80
  end
75
81
 
76
82
  def method_missing(name, *args)
83
+ morph :nothing
77
84
  super unless respond_to_missing?(name)
78
85
  state.each do |k, v|
79
86
  component.instance_variable_set(k, v)
@@ -15,7 +15,7 @@ module ViewComponentReflex
15
15
 
16
16
  def self.store_state(request, key, new_state = {})
17
17
  VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s] ||= {}
18
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key] ||= {}
18
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key] = {}
19
19
  new_state.each do |k, v|
20
20
  VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key][k] = v
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua LeBlanc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: stimulus_reflex
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: 3.3.0.pre2
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 3.3.0.pre2
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: view_component
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -69,9 +69,9 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - app/components/view_component_reflex/component.rb
72
- - app/reflexes/view_component_reflex/reflex.rb
73
72
  - lib/view_component_reflex.rb
74
73
  - lib/view_component_reflex/engine.rb
74
+ - lib/view_component_reflex/reflex.rb
75
75
  - lib/view_component_reflex/state_adapter/memory.rb
76
76
  - lib/view_component_reflex/state_adapter/session.rb
77
77
  - lib/view_component_reflex/version.rb