@@ -45,14 +45,12 @@ def config
45
45
delegate :content_security_policy_nonce , to : :helpers
46
46
47
47
# Config option that strips trailing whitespace in templates before compiling them.
48
- class_attribute :__vc_cache_dependencies , instance_accessor : false , instance_predicate : false , default : [ ]
48
+ class_attribute :__vc_cache_dependencies , default : [ ]
49
49
class_attribute :__vc_strip_trailing_whitespace , instance_accessor : false , instance_predicate : false
50
50
self . __vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
51
51
52
52
attr_accessor :__vc_original_view_context
53
53
54
-
55
-
56
54
# Components render in their own view context. Helpers and other functionality
57
55
# require a reference to the original Rails view context, an instance of
58
56
# `ActionView::Base`. Use this method to set a reference to the original
@@ -295,6 +293,12 @@ def __vc_request
295
293
@__vc_request ||= controller . request if controller . respond_to? ( :request )
296
294
end
297
295
296
+ def view_cache_dependencies
297
+ return unless __vc_cache_dependencies . present? && __vc_cache_dependencies . any?
298
+
299
+ __vc_cache_dependencies . map { |dep | send ( dep ) } . compact
300
+ end
301
+
298
302
# The content passed to the component instance as a block.
299
303
#
300
304
# @return [String]
@@ -458,7 +462,8 @@ def safe_output_postamble
458
462
# config.view_component.generate.preview = true
459
463
# ```
460
464
#
461
- # Defaults to `false`.
465
+ # Defaults to `false`
466
+ #
462
467
463
468
class << self
464
469
# The file path of the component Ruby file.
@@ -472,6 +477,8 @@ class << self
472
477
# @private
473
478
attr_accessor :virtual_path
474
479
480
+
481
+
475
482
# Find sidecar files for the given extensions.
476
483
#
477
484
# The provided array of extensions is expected to contain
@@ -514,16 +521,8 @@ def sidecar_files(extensions)
514
521
( sidecar_files - [ identifier ] + sidecar_directory_files + nested_component_files ) . uniq
515
522
end
516
523
517
-
518
-
519
524
def cache_on ( *args )
520
- self . __vc_cache_dependencies . push ( *args )
521
- end
522
-
523
- def view_cache_dependencies
524
- return unless __vc_cache_dependencies . any?
525
-
526
- __vc_cache_dependencies . map { |dep | send ( dep ) } . compact
525
+ __vc_cache_dependencies . push ( *args )
527
526
end
528
527
529
528
# Render a component for each element in a collection ([documentation](/guide/collections)):
@@ -591,6 +590,8 @@ def render_template_for(variant = nil, format = nil)
591
590
child . instance_variable_set ( :@__vc_ancestor_calls , vc_ancestor_calls )
592
591
end
593
592
593
+ child . __vc_cache_dependencies = self . __vc_cache_dependencies . dup
594
+
594
595
super
595
596
end
596
597
0 commit comments