view_component_reflex 3.3.15 → 3.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/view_component_reflex/component.rb +4 -0
- data/lib/view_component_reflex/reflex_factory.rb +1 -1
- 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: e8dea2221ccd4d6ffabc20687fcab334820ded3d9d40d14242f132c730942126
|
4
|
+
data.tar.gz: 06e5f08ea176338c87b63ade59d4fc5e9a364b0f53e83410f57372ba3f2fdfdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '029140d0e31153061345aa774ca8a13b67615323411b378871f4ea94e05fbb4a112121a6b98c6d2ae3d5d3b267d58d0951869f41ba33fab8f2442e1650c9e296'
|
7
|
+
data.tar.gz: 576d8bc75bfe2a2250a3d874463276d50b8cdc2fa8092461cdf5738e4bd3c0a166ea131f5c01758226dcf400b3bb708e862e49bad6f3e07f4ebc81ebe2a65568
|
data/README.md
CHANGED
@@ -233,6 +233,34 @@ def after_state_initialized(parameters_changed)
|
|
233
233
|
end
|
234
234
|
```
|
235
235
|
|
236
|
+
### reflex_methods
|
237
|
+
|
238
|
+
By default, all public instance methods are available as reflex methods. You can override this to explicitly define which methods should be available as reflexes:
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
class MyComponent < ViewComponentReflex::Component
|
242
|
+
def self.reflex_methods
|
243
|
+
[:increment, :decrement, :reset]
|
244
|
+
end
|
245
|
+
|
246
|
+
def increment
|
247
|
+
@count += 1
|
248
|
+
end
|
249
|
+
|
250
|
+
def decrement
|
251
|
+
@count -= 1
|
252
|
+
end
|
253
|
+
|
254
|
+
def reset
|
255
|
+
@count = 0
|
256
|
+
end
|
257
|
+
|
258
|
+
def private_helper_method
|
259
|
+
# This won't be available as a reflex since it's not in reflex_methods
|
260
|
+
end
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
236
264
|
## Custom reflex base class
|
237
265
|
Reflexes typically inherit from a base ApplicationReflex. You can define the base class for a view_component_reflex by using the `reflex_base_class` accessor.
|
238
266
|
The parent class must inherit ViewComponentReflex::Reflex, and will throw an error if it does not.
|
@@ -78,6 +78,10 @@ module ViewComponentReflex
|
|
78
78
|
name.chomp("Component").underscore.dasherize.gsub("/", "--")
|
79
79
|
end
|
80
80
|
|
81
|
+
def self.reflex_methods
|
82
|
+
public_instance_methods - ViewComponentReflex::Component.instance_methods - [:call, :"_call_#{name.underscore}"]
|
83
|
+
end
|
84
|
+
|
81
85
|
def stimulus_reflex?
|
82
86
|
helpers.controller.instance_variable_get(:@stimulus_reflex)
|
83
87
|
end
|
@@ -39,7 +39,7 @@ module ViewComponentReflex
|
|
39
39
|
# class.
|
40
40
|
# This replaces the old method_missing implementation, and passes more strict validation of recent SR versions
|
41
41
|
def build_reflex_instance
|
42
|
-
reflex_methods = @component.
|
42
|
+
reflex_methods = @component.reflex_methods
|
43
43
|
component_allocate = @component.allocate
|
44
44
|
Class.new(@component.reflex_base_class).tap do |klass|
|
45
45
|
klass.instance_variable_set(:@__method_parameters, {})
|