view_component_reflex 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 457de938235885451ab74f7c2a5136bc6e87443467f8ae7944eb27fb23f1dbdd
4
- data.tar.gz: 4b6c6b6152facd010da5f74355e46a9f8db492e8b84e54563b27179f3edf7a93
3
+ metadata.gz: 9b88985bd86d0a17dad82c4f01452e0f62a90c6b46984e9df1de0bc7242e1788
4
+ data.tar.gz: da3801c7566583a2325d60cab55f35c5f3bca0a6031419f05279df7d46de2a12
5
5
  SHA512:
6
- metadata.gz: 300ec189d65159384a26ee644ab7fa2deb3e9609fea703f004822cbde354af444ef2c4f4ed050b3770c4b2f19b81c1f0e710be673f1f570445d41216bb8ab2b7
7
- data.tar.gz: 304db5f0fa2e8a98d6cf97603e17c110faa84f82fe06cfdd675f154b69bad27841474dc7ca7a048be500d65ccf957af9545599339acb35e24a8babccbe4dc07c
6
+ metadata.gz: 33f8f7db2aac6d2808ad1b88eff827c0d91e8b16606a59c7dc6cab16f1b805f329162167026f0d7698556ac5fbd00b98d0ec8da720c91b0015459218e46da1fb
7
+ data.tar.gz: 5ff2eddfcbfbdf41c7caf47fe7577c737b59dd705affef9e56d0ae3f585c34cff2c5a11d41385c04866c4142f8119f7f7108cb3cf73da19bc3fdca3765f50fd3
@@ -201,7 +201,8 @@ module ViewComponentReflex
201
201
  [
202
202
  :@view_context, :@lookup_context, :@view_renderer, :@view_flow,
203
203
  :@virtual_path, :@variant, :@current_template, :@output_buffer, :@key,
204
- :@helpers, :@controller, :@request, :@tag_builder, :@state_initialized
204
+ :@helpers, :@controller, :@request, :@tag_builder, :@state_initialized,
205
+ :@_content_evaluated, :@_render_in_block
205
206
  ]
206
207
  end
207
208
 
@@ -5,6 +5,13 @@ module ViewComponentReflex
5
5
  attr_accessor :component_class
6
6
  end
7
7
 
8
+ # pretty sure I can't memoize this because we need
9
+ # to re-render every time
10
+ def controller_document
11
+ controller.process(params[:action])
12
+ Nokogiri::HTML(controller.response.body)
13
+ end
14
+
8
15
  def refresh!(primary_selector = nil, *rest)
9
16
  save_state
10
17
 
@@ -14,10 +21,8 @@ module ViewComponentReflex
14
21
  if primary_selector
15
22
  prevent_refresh!
16
23
 
17
- controller.process(params[:action])
18
- document = Nokogiri::HTML(controller.response.body)
19
24
  [primary_selector, *rest].each do |s|
20
- html = document.css(s)
25
+ html = controller_document.css(s)
21
26
  if html.present?
22
27
  CableReady::Channels.instance[stream].morph(
23
28
  selector: s,
@@ -41,7 +46,7 @@ module ViewComponentReflex
41
46
  @stream = channel
42
47
  end
43
48
 
44
- def refresh_component!
49
+ def component_document
45
50
  component.tap do |k|
46
51
  k.define_singleton_method(:initialize_component) do
47
52
  @key = element.dataset[:key]
@@ -49,14 +54,27 @@ module ViewComponentReflex
49
54
  end
50
55
 
51
56
  document = Nokogiri::HTML(component.render_in(controller.view_context))
57
+ end
58
+
59
+ def refresh_component!
52
60
  CableReady::Channels.instance[stream].morph(
53
61
  selector: selector,
54
62
  children_only: true,
55
- html: document.css(selector).inner_html,
63
+ html: component_document.css(selector).inner_html,
56
64
  permanent_attribute_name: "data-reflex-permanent",
57
65
  )
58
66
  end
59
67
 
68
+ def default_morph
69
+ save_state
70
+ html = if component.can_render_to_string?
71
+ component_document.css(selector).to_html
72
+ else
73
+ controller_document.css(selector).to_html
74
+ end
75
+ morph selector, html
76
+ end
77
+
60
78
  def stimulus_reflex_data
61
79
  {
62
80
  reflex_id: reflex_id,
@@ -96,7 +114,6 @@ module ViewComponentReflex
96
114
  end
97
115
 
98
116
  def method_missing(name, *args, &blk)
99
- morph :nothing
100
117
  super unless respond_to_missing?(name)
101
118
 
102
119
  state.each do |k, v|
@@ -105,7 +122,11 @@ module ViewComponentReflex
105
122
 
106
123
  component.send(name, *args, &blk)
107
124
 
108
- refresh! unless @prevent_refresh
125
+ if @prevent_refresh
126
+ morph :nothing
127
+ else
128
+ default_morph
129
+ end
109
130
  end
110
131
 
111
132
  def prevent_refresh!
@@ -9,6 +9,7 @@ module ViewComponentReflex
9
9
  new_state.each do |k, v|
10
10
  state(request, key)[k] = v
11
11
  end
12
+ p new_state
12
13
  store = request.session.instance_variable_get("@by")
13
14
  store.commit_session request, controller.response
14
15
  end
@@ -18,6 +19,7 @@ module ViewComponentReflex
18
19
  new_state.each do |k, v|
19
20
  request.session[key][k] = v
20
21
  end
22
+ p new_state
21
23
  end
22
24
 
23
25
  def self.wrap_write_async
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '3.1.7'
2
+ VERSION = '3.1.8'
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: 3.1.7
4
+ version: 3.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua LeBlanc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails