Skip to content

Commit

Permalink
fix: reduce UnboundMethod objects by memoizing initialize_parameters (V…
Browse files Browse the repository at this point in the history
…iewComponent#1868)

Co-authored-by: Cameron Dutro <[email protected]>
  • Loading branch information
2 people authored and claudiob committed Dec 22, 2023
1 parent 826fa08 commit 6d3f53b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ nav_order: 5

*Alexandre Ignjatovic*

* Reduce UnboundMethod objects by memoizing initialize_parameters

*Rainer Borene*

* Improve docs about inline templates interpolation.

*Hans Lemuet*
Expand Down
3 changes: 2 additions & 1 deletion lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def identifier
# @param parameter [Symbol] The parameter name used when rendering elements of a collection.
def with_collection_parameter(parameter)
@provided_collection_parameter = parameter
@initialize_parameters = nil
end

# Strips trailing whitespace from templates before compiling them.
Expand Down Expand Up @@ -648,7 +649,7 @@ def initialize_parameter_names
end

def initialize_parameters
instance_method(:initialize).parameters
@initialize_parameters ||= instance_method(:initialize).parameters
end

def provided_collection_parameter
Expand Down

0 comments on commit 6d3f53b

Please sign in to comment.