view_component_reflex 1.1.1 → 1.2.0
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: 4ed2f845769bba6d5142bef6d6fc601b44841080c49ee47abc0036801f62b145
|
4
|
+
data.tar.gz: 73e625d1948e5b477def8e098a4a4d55b9a02763c575e1d4bdd4c734e0f208b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76c5b53b3acb0fa68084b762ad14fddbaa0aee1d0b9bbe67f33910f088e7b60062bf5dcf61c7703932b2cfa228f4bccfc768e6b9ab64253397e3483efd50cfb5
|
7
|
+
data.tar.gz: 077a34955920288651b183d77971d30eb4fbfeabe45aaa799d78f2ea242cb46f328d23223508d053e53210c00e9aeb570e9d234b571aba3005e57b6448afd5fc
|
data/README.md
CHANGED
@@ -53,6 +53,13 @@ end
|
|
53
53
|
<%= render(TodoComponent.with_collection(Todo.all)) %>
|
54
54
|
```
|
55
55
|
|
56
|
+
## API
|
57
|
+
|
58
|
+
### permit_parameter?(initial_param, new_params)
|
59
|
+
If a new parameter is passed to the component during rendering, it is used instead of what's in state.
|
60
|
+
If you're storing instances in state, you can use this to properly compare them.
|
61
|
+
|
62
|
+
|
56
63
|
## Custom State Adapters
|
57
64
|
|
58
65
|
ViewComponentReflex uses session for its state by default. To change this, add
|
@@ -76,13 +83,13 @@ class YourAdapter
|
|
76
83
|
end
|
77
84
|
|
78
85
|
##
|
79
|
-
# set_state is used to modify the state.
|
80
|
-
# access to the request, as well as the controller and other useful objects.
|
86
|
+
# set_state is used to modify the state.
|
81
87
|
#
|
82
|
-
#
|
88
|
+
# request - a rails request object
|
89
|
+
# controller - the current controller
|
83
90
|
# key - a unique string that identifies the component
|
84
91
|
# new_state - the new state to set
|
85
|
-
def self.set_state(
|
92
|
+
def self.set_state(request, controller, key, new_state)
|
86
93
|
# update the state
|
87
94
|
end
|
88
95
|
|
@@ -72,7 +72,7 @@ module ViewComponentReflex
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def set_state(new_state = {})
|
75
|
-
ViewComponentReflex::Engine.state_adapter.set_state(
|
75
|
+
ViewComponentReflex::Engine.state_adapter.set_state(request, controller, element.dataset[:key], new_state)
|
76
76
|
end
|
77
77
|
|
78
78
|
def state
|
@@ -125,6 +125,10 @@ module ViewComponentReflex
|
|
125
125
|
nil
|
126
126
|
end
|
127
127
|
|
128
|
+
def permit_parameter?(initial_param, new_param)
|
129
|
+
initial_param != new_param
|
130
|
+
end
|
131
|
+
|
128
132
|
def key
|
129
133
|
# initialize session state
|
130
134
|
if !stimulus_reflex? || session[@key].nil?
|
@@ -140,9 +144,13 @@ module ViewComponentReflex
|
|
140
144
|
new_state[k] = instance_variable_get(k)
|
141
145
|
end
|
142
146
|
ViewComponentReflex::Engine.state_adapter.store_state(request, @key, new_state)
|
147
|
+
ViewComponentReflex::Engine.state_adapter.store_state(request, "#{@key}_initial", new_state)
|
143
148
|
else
|
149
|
+
initial_state = ViewComponentReflex::Engine.state_adapter.state(request, "#{@key}_initial")
|
144
150
|
ViewComponentReflex::Engine.state_adapter.state(request, @key).each do |k, v|
|
145
|
-
|
151
|
+
unless permit_parameter?(initial_state[k], instance_variable_get(k))
|
152
|
+
instance_variable_set(k, v)
|
153
|
+
end
|
146
154
|
end
|
147
155
|
end
|
148
156
|
@key
|
@@ -5,12 +5,12 @@ module ViewComponentReflex
|
|
5
5
|
request.session[key] ||= {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.set_state(
|
8
|
+
def self.set_state(request, controller, key, new_state)
|
9
9
|
new_state.each do |k, v|
|
10
|
-
state(
|
10
|
+
state(request, key)[k] = v
|
11
11
|
end
|
12
|
-
store =
|
13
|
-
store.commit_session
|
12
|
+
store = request.session.instance_variable_get("@by")
|
13
|
+
store.commit_session request, controller.response
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.store_state(request, key, new_state = {})
|