Skip to content

Commit

Permalink
getStyleObjectFromCSS to compute when cache miss (#3024)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx authored and thegreatercurve committed Nov 25, 2022
1 parent ab2e08c commit 507794f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/lexical-selection/flow/LexicalSelection.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare export function $cloneContents<T: LexicalNode>(
declare export function $cloneWithProperties<T: LexicalNode>(node: T): T;
declare export function getStyleObjectFromCSS(css: string): {
[string]: string,
} | null;
};
declare export function $patchStyleText(
selection: RangeSelection | GridSelection,
patch: {
Expand Down
11 changes: 7 additions & 4 deletions packages/lexical-selection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,13 @@ function $cloneContentsImpl(
invariant(false, 'TODO');
}

export function getStyleObjectFromCSS(
css: string,
): Record<string, string> | null {
return cssToStyles.get(css) || null;
export function getStyleObjectFromCSS(css: string): Record<string, string> {
let value = cssToStyles.get(css);
if (value === undefined) {
value = getStyleObjectFromRawCSS(css);
cssToStyles.set(css, value);
}
return value;
}

function getStyleObjectFromRawCSS(css: string): Record<string, string> {
Expand Down

0 comments on commit 507794f

Please sign in to comment.