Skip to content

Commit d45d9cd

Browse files
optimized to prevent repetitive calls
1 parent 71766f6 commit d45d9cd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/components/advanced-range-control/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const AdvancedRangeControl = props => {
116116
if ( props.marks && derivedValue ) {
117117
// Check if the current value exists in the marks only by their CSS variable name
118118
// to match in case the fallback size changes.
119-
const matchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === getCSSVarName( derivedValue ) )
119+
const derivedValueCssVarName = getCSSVarName( derivedValue )
120+
const matchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === derivedValueCssVarName )
120121
isMarkValue = !! matchedMark
121122
if ( matchedMark ) {
122123
derivedValue = matchedMark.value

src/components/four-range-control/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,16 @@ const FourRangeControl = memo( props => {
200200
if ( props.marks && firstValue ) {
201201
// Check if the current value exists in the marks only by their CSS variable name
202202
// to match in case the fallback size changes.
203-
const firstMatchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === getCSSVarName( firstValue ) )
203+
const firstValueCssVarName = getCSSVarName( firstValue )
204+
const firstMatchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === firstValueCssVarName )
204205
isMarkValue.first = !! firstMatchedMark
205206
if ( firstMatchedMark ) {
206207
firstValue = firstMatchedMark.value
207208
}
208209

209210
[ 'top', 'right', 'bottom', 'left' ].forEach( side => {
210-
const matchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === getCSSVarName( value[ side ] ) )
211+
const sideCssVarName = getCSSVarName( value[ side ] )
212+
const matchedMark = props.marks.find( mark => getCSSVarName( mark.value ) === sideCssVarName )
211213
isMarkValue[ side ] = !! matchedMark
212214
if ( matchedMark ) {
213215
value[ side ] = matchedMark.value

0 commit comments

Comments
 (0)