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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbeda9f2f7f4f327afd6da54bcd82ac6871eab33efa07ae1901ccd8d002801d2
|
4
|
+
data.tar.gz: bb5afb39f319dadfcf68272cbee6762286d475c1ce93382e611f722dd6d46baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
42
|
-
(@
|
43
|
-
|
44
|
-
|
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
|
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
|
+
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-
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|