view_component_reflex 0.2.4 → 0.2.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: e5ffa83358af12b225a6a5d4e7fc16a27275e1f2815b2f5e6105a555d7d3faa8
4
- data.tar.gz: 2822a3c179dac3550eb1be5c7d30f997cd8942422429d2af92f167880652f28c
3
+ metadata.gz: fbeda9f2f7f4f327afd6da54bcd82ac6871eab33efa07ae1901ccd8d002801d2
4
+ data.tar.gz: bb5afb39f319dadfcf68272cbee6762286d475c1ce93382e611f722dd6d46baa
5
5
  SHA512:
6
- metadata.gz: f85e4d51fef8d3ba242a48b9b8c3f5c800cbd746582c055d0cb68eba6b6309b2678362fd18b55fec103a1a26d08df728603304ccb5c2f7d0f9bca6c96ce24de6
7
- data.tar.gz: 0a9624dff9b4127e59d28ecb0a574186dda9214f772cf332cd23aeca740ef8a3633ff0066d9c8e323fc4c612efb87e81fb9ac24c70aaaab3fc8ece07561bd243
6
+ metadata.gz: 27d42f4f6a349223d3a0d354b31a0d37dacd51fef18450c254c8353cadb8018bc62dbccefcb99e2a5cff3bf6d61240b6836eebfb8af0974448baf57f2c4a9bc3
7
+ data.tar.gz: fac906b5ad974f51b0023f04a58ba9164d38348b181a6f22e6193664d77c93ef5dd53da31abe4a94cf9f39d6ecffdd5fbf2654831f07de810c712751237c3204
@@ -30,7 +30,7 @@ module ViewComponentReflex
30
30
  end
31
31
 
32
32
  # key is required if you're using state
33
- # We can't initialize the session state in the initiale method
33
+ # We can't initialize the session state in the initial method
34
34
  # because it doesn't have a view_context yet
35
35
  # This is the next best place to do it
36
36
  def key
@@ -38,10 +38,10 @@ module ViewComponentReflex
38
38
 
39
39
  # initialize session state
40
40
  if session[@key].nil?
41
- session[@key] = {}
42
- (@state ||= {}).each do |key, v|
43
- session[@key][key] = v
44
- end
41
+ store_state(@key)
42
+ store_state("#{@key}_initial")
43
+ else
44
+ reconcile_state
45
45
  end
46
46
  @key
47
47
  end
@@ -49,5 +49,28 @@ module ViewComponentReflex
49
49
  def state
50
50
  session[key]
51
51
  end
52
+
53
+ private
54
+
55
+ # The passed state should always match the initial state of the component
56
+ # if it doesn't, we need to reset the state to the passed value.
57
+ #
58
+ # This handles cases where your initialize_state param computes some value that changes
59
+ # initialize_state({ transaction: @customer.transactions.first })
60
+ # if you delete the first transaction, that ^ is no longer valid. We need to update the state.
61
+ def reconcile_state
62
+ session["#{@key}_initial"].each do |k, v|
63
+ if @state[k] != v
64
+ session[@key][k] = @state[k]
65
+ end
66
+ end
67
+ end
68
+
69
+ def store_state(a_key)
70
+ session[a_key] = {}
71
+ (@state ||= {}).each do |key, v|
72
+ session[a_key][key] = v
73
+ end
74
+ end
52
75
  end
53
76
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.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: 0.2.4
4
+ version: 0.2.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-06-04 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails