view_component_reflex 3.0.0 → 3.0.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: 047aa78feb4675abeb3bb5a5ed86ea4071c6a22fef3e06fb2806b04d651898cd
4
- data.tar.gz: 5c0cc3c3c6fca877e8b2d8a595c601ddea90b892a62367af6abed6099a6b1b81
3
+ metadata.gz: 0c063a5b69263cf48e6a92937e65a73cd1a2c5e00577734f62b7cbf6186604d3
4
+ data.tar.gz: 26ec1a060c0283a906df2bcda4cd11110bb31ebe69e9d5c741cf568d6dabd7de
5
5
  SHA512:
6
- metadata.gz: 0f3f2e6f15c43e47aa3cdcd39632f4e2d7d76dd7065dcfd38b718db0e34ac100fed7268371660994c402a9c0aacd07635a935f088cec49cebbbcbccae6533aea
7
- data.tar.gz: 56fa191797a8d3f757457a7a8c94f4394304ca0dd201639c0d47225a7f7be7ceb9b349641805783538325e884431e483a5b51714c4f75f26826912c953474d7c
6
+ metadata.gz: b7f55e4e85f42a9c9b0044710f8f2c295e0c13350bfc26f1c940626b581e68a851feb1c7cf4c54124a7e96ac9ade6565b1e3361f789e0efbc16644c78bc906b2
7
+ data.tar.gz: aa24fa075eae92847e04931a1278b20358472fc9fdb00079bb1f0b774d84f5a3a047f90d61e42295a578999a7c69ec12e152847d77ecf6a4236554d4b4c38605
data/README.md CHANGED
@@ -359,6 +359,21 @@ end
359
359
 
360
360
  StimulusReflex 3.4 introduced a fix that merges the current `request.env` and provides the CSRF token to fetch the session.
361
361
 
362
+ ## Help, my instance variables do not persist into the session
363
+
364
+ These instance variable names are not working and unsafe:
365
+
366
+ ```rb
367
+ def unsafe_instance_variables
368
+ [
369
+ :@view_context, :@lookup_context, :@view_renderer, :@view_flow,
370
+ :@virtual_path, :@variant, :@current_template, :@output_buffer, :@key,
371
+ :@helpers, :@controller, :@request, :@tag_builder, :@initialized_state
372
+ ]
373
+ end
374
+ ```
375
+ Please use a different name to be able to save them to the session.
376
+
362
377
  ## Anycable
363
378
 
364
379
  @sebyx07 provided a solution to use anycable (https://github.com/joshleblanc/view_component_reflex/issues/23#issue-721786338)
@@ -47,7 +47,7 @@ module ViewComponentReflex
47
47
  end
48
48
 
49
49
  def self.stimulus_controller
50
- name.chomp("Component").underscore.dasherize
50
+ name.chomp("Component").underscore.dasherize.gsub("/", "--")
51
51
  end
52
52
 
53
53
  def stimulus_reflex?
@@ -57,7 +57,7 @@ module ViewComponentReflex
57
57
  def component_controller(opts_or_tag = :div, opts = {}, &blk)
58
58
  init_key
59
59
 
60
- tag = :div
60
+ tag = :di
61
61
  options = if opts_or_tag.is_a? Hash
62
62
  opts_or_tag
63
63
  else
@@ -1,5 +1,6 @@
1
1
  require "stimulus_reflex"
2
2
  require 'view_component_reflex/reflex_factory'
3
+ require "view_component_reflex/state_adapter/base"
3
4
  require "view_component_reflex/state_adapter/session"
4
5
  require "view_component_reflex/state_adapter/memory"
5
6
  require "view_component_reflex/state_adapter/redis"
@@ -13,13 +13,16 @@ module ViewComponentReflex
13
13
  reflex_name, _ = target.split("#")
14
14
  reflex_name = reflex_name.camelize
15
15
  component_name = reflex_name.end_with?("Reflex") ? reflex_name[0...-6] : reflex_name
16
- if component_name.end_with?("Component")
17
- begin
18
- component_name.constantize.init_stimulus_reflex
19
- rescue
20
- p "Tried to initialize view_component_reflex on #{component_name}, but it's not a view_component_reflex"
21
- end
16
+ component = begin
17
+ component_name.constantize
18
+ rescue
19
+ # Since every reflex runs through this monkey patch, we're just going to ignore the ones that aren't for components
20
+ end
22
21
 
22
+ if component&.respond_to?(:init_stimulus_reflex)
23
+ component.init_stimulus_reflex
24
+ else
25
+ p "Tried to initialize view_component_reflex on #{component_name}, but it's not a view_component_reflex"
23
26
  end
24
27
  receive_original(data)
25
28
  end
@@ -0,0 +1,18 @@
1
+ module ViewComponentReflex
2
+ module StateAdapter
3
+ class Base
4
+
5
+ private
6
+
7
+ def self.extract_id(request)
8
+ session = request&.session
9
+ if session.respond_to? :id
10
+ session.id.to_s
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,10 +1,12 @@
1
1
  VIEW_COMPONENT_REFLEX_MEMORY_STATE = {}
2
2
  module ViewComponentReflex
3
3
  module StateAdapter
4
- class Memory
4
+ class Memory < Base
5
5
  def self.state(request, key)
6
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s] ||= {}
7
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key] ||= {}
6
+ id = extract_id(request)
7
+
8
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[id] ||= {}
9
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[id][key] ||= {}
8
10
  end
9
11
 
10
12
  def self.set_state(request, _, key, new_state)
@@ -14,10 +16,12 @@ module ViewComponentReflex
14
16
  end
15
17
 
16
18
  def self.store_state(request, key, new_state = {})
17
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s] ||= {}
18
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key] = {}
19
+ id = extract_id(request)
20
+
21
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[id] ||= {}
22
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[id][key] = {}
19
23
  new_state.each do |k, v|
20
- VIEW_COMPONENT_REFLEX_MEMORY_STATE[request.session.id.to_s][key][k] = v
24
+ VIEW_COMPONENT_REFLEX_MEMORY_STATE[id][key][k] = v
21
25
  end
22
26
  end
23
27
 
@@ -10,7 +10,7 @@
10
10
 
11
11
  module ViewComponentReflex
12
12
  module StateAdapter
13
- class Redis
13
+ class Redis < Base
14
14
  attr_reader :client, :ttl
15
15
 
16
16
  def initialize(redis_opts:, ttl: 3600)
@@ -67,8 +67,9 @@ module ViewComponentReflex
67
67
  end
68
68
 
69
69
  def get_key(request, key)
70
- "#{request.session.id.to_s}_#{key}_session_reflex_redis"
70
+ id = Redis.extract_id(request)
71
+ "#{id}_#{key}_session_reflex_redis"
71
72
  end
72
73
  end
73
74
  end
74
- end
75
+ end
@@ -1,6 +1,6 @@
1
1
  module ViewComponentReflex
2
2
  module StateAdapter
3
- class Session
3
+ class Session < Base
4
4
  def self.state(request, key)
5
5
  request.session[key] ||= {}
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.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: 3.0.0
4
+ version: 3.0.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-12-06 00:00:00.000000000 Z
11
+ date: 2021-01-04 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: 3.4.0.pre8
39
+ version: 3.4.0
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: 3.4.0.pre8
46
+ version: 3.4.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: view_component
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  description: Allow stimulus reflexes in a view component
62
76
  email:
63
77
  - joshleblanc94@gmail.com
@@ -73,6 +87,7 @@ files:
73
87
  - lib/view_component_reflex/engine.rb
74
88
  - lib/view_component_reflex/reflex.rb
75
89
  - lib/view_component_reflex/reflex_factory.rb
90
+ - lib/view_component_reflex/state_adapter/base.rb
76
91
  - lib/view_component_reflex/state_adapter/memory.rb
77
92
  - lib/view_component_reflex/state_adapter/redis.rb
78
93
  - lib/view_component_reflex/state_adapter/session.rb