-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf881d3
commit d5f6797
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
///Very simple type that will cache the result of style queries. | ||
public final class StylingCache { | ||
private var cache = [Query: Style]() | ||
private let styler: any Styling | ||
|
||
public init(styler: any Styling) { | ||
self.styler = styler | ||
} | ||
} | ||
|
||
extension StylingCache: Styling { | ||
public func style(for query: Query) -> Style? { | ||
if let style = cache[query] { | ||
return style | ||
} | ||
|
||
let style = styler.style(for: query) | ||
|
||
self.cache[query] = style | ||
|
||
return style | ||
} | ||
} |