view_component_reflex 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/app/components/view_component_reflex/component.rb +6 -2
- data/lib/view_component_reflex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9ea0fbad8a65f59a333d8367315adb6a13bb52f7d6dcf35fccd8ad71b8de9c
|
4
|
+
data.tar.gz: 29846c963ffb334ac158b2658566cbb3a2cb1248e8e67febd0d0a034af134b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99478df0b1a5ffa4784aea880b7f757299a706e0ff35a2b6a692bfecbfe64b0cd483b730c115f0574f75f5566fb50770ce2e0d079e646e5ce01113b57adfe780
|
7
|
+
data.tar.gz: d6802a9810a10dbdef2e4f82ddfeb63e766973f1151b6f87799ebfac3513e446aaaf56649c6f31f2bf24a617ece938b539e3b317354189cee1ff99488db70650
|
data/README.md
CHANGED
@@ -11,12 +11,15 @@ To add a reflex to your component, use the `reflex` method.
|
|
11
11
|
```ruby
|
12
12
|
reflex :my_cool_reflex do
|
13
13
|
# do stuff
|
14
|
+
refresh!
|
14
15
|
end
|
15
16
|
```
|
16
17
|
|
17
18
|
This will act as if you created a reflex with the method `my_cool_stuff`. To call this reflex, add `data-reflex="click->MyComponentReflex#my_cool_reflex"`, just like you're
|
18
19
|
using stimulus reflex.
|
19
20
|
|
21
|
+
#####note: A reflex will not automatically re-render the component upon its completion. A component will re-render whenever the `set_state` or `refresh!` method is called.
|
22
|
+
|
20
23
|
In addition to calling reflexes, there is a rudimentary state system. You can initialize component-local state with `initialize_state(obj)`, where `obj` is a hash.
|
21
24
|
|
22
25
|
You can access state with the `state` helper. See the code below for an example. Calling `set_state` will set the state,
|
@@ -12,8 +12,7 @@ module ViewComponentReflex
|
|
12
12
|
ViewComponentReflex::Engine.state_adapter.state(request, element.dataset[:key])
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
ViewComponentReflex::Engine.state_adapter.set_state(self, element.dataset[:key], new_state)
|
15
|
+
def refresh!
|
17
16
|
@channel.render_page_and_broadcast_morph(self, nil, {
|
18
17
|
dataset: element.dataset.to_h,
|
19
18
|
args: [],
|
@@ -25,6 +24,11 @@ module ViewComponentReflex
|
|
25
24
|
})
|
26
25
|
end
|
27
26
|
|
27
|
+
def set_state(new_state = {})
|
28
|
+
ViewComponentReflex::Engine.state_adapter.set_state(self, element.dataset[:key], new_state)
|
29
|
+
refresh!
|
30
|
+
end
|
31
|
+
|
28
32
|
before_reflex do |reflex, *args|
|
29
33
|
instance_exec(*args, &self.class.callbacks[self.method_name.to_sym]) if self.class.callbacks.include?(self.method_name.to_sym)
|
30
34
|
throw :abort
|