Skip to content

Commit 4374cd7

Browse files
refact: Cache color options
1 parent 6e8febf commit 4374cd7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

config/fields/color.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
* to directly select them
5252
*/
5353
'options' => function (array $options = []): array {
54+
// make sure to flush the options cache when
55+
// new options are being passed
56+
$this->optionsCache = null;
5457
return $options;
5558
}
5659
],
@@ -59,6 +62,14 @@
5962
return Str::lower($this->default);
6063
},
6164
'options' => function (): array {
65+
return $this->optionsCache ??= $this->getOptions();
66+
}
67+
],
68+
'methods' => [
69+
'emptyValue' => function () {
70+
return '';
71+
},
72+
'getOptions' => function () {
6273
// resolve options to support manual arrays
6374
// alongside api and query options
6475
$props = FieldOptions::polyfill($this->props);
@@ -103,11 +114,6 @@
103114
}
104115

105116
return $options;
106-
}
107-
],
108-
'methods' => [
109-
'emptyValue' => function () {
110-
return '';
111117
},
112118
'isColor' => function (string $value): bool {
113119
return

0 commit comments

Comments
 (0)