-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Keep foldedComponentIds as a string Seems the only use just joins the contents on every read, so we can do it on write instead. * Build className string manually Items are added to the array only to be filtered out again and then the remaining ones get joined. This performs better. * Use Set for domElements More accurately represents the collection and gives O(1) lookup performance. * Read value once * Remove unnecessary casting & array check `flatten` always returns an array, and `join` doesn't seem to care what type it is. * Simplify objToCssArray * Make names a local variable It's not accessed outside of this function and is always reset at the start. * Build string directly instead of joining array elements * Add util function for joining string arrays `[...].join()` for an array of strings only becomes more performant with many thousands of items. With 10 strings, this function is ~1.5x faster in Chrome and ~3x faster in Firefox. * Optimize hyphenateStyleName Just replacing regex with manual iteration. This could be several times faster if we checked for the "ms-" prefix within the loop, but it makes the function pretty unreadable.
- Loading branch information
1 parent
2b4f6cb
commit 4d4e63c
Showing
13 changed files
with
110 additions
and
58 deletions.
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
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
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
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
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
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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
/** | ||
* Convenience function for joining strings to form className chains | ||
*/ | ||
export default function joinStrings(a: string | undefined, b: string): string { | ||
export function joinStrings(a: string | undefined, b: string): string { | ||
return a && b ? `${a} ${b}` : a || b; | ||
} | ||
|
||
export function joinStringArray(arr: string[], sep?: string): string { | ||
if (arr.length === 0) { | ||
return ''; | ||
} | ||
|
||
let result = arr[0]; | ||
for (let i = 1; i < arr.length; i++) { | ||
result += sep ? sep + arr[i] : arr[i]; | ||
} | ||
return result; | ||
} |
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