Skip to content

Commit

Permalink
memoized ui/common device.isApple, compute device.shareIcon when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 17, 2024
1 parent bfa44ab commit ab14fa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ui/analyse/src/study/studyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function buttons(root: AnalyseCtrl): VNode {
count: root.data.analysis && '✓',
}),
toolButton({ ctrl, tab: 'multiBoard', hint: 'Multiboard', icon: iconTag(licon.Multiboard) }),
toolButton({ ctrl, tab: 'share', hint: i18n.study.shareAndExport, icon: iconTag(shareIcon) }),
toolButton({ ctrl, tab: 'share', hint: i18n.study.shareAndExport, icon: iconTag(shareIcon()) }),
!ctrl.relay &&
!ctrl.data.chapter.gamebook &&
h('span.help', {
Expand Down
8 changes: 5 additions & 3 deletions ui/common/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export const isSafari = (): boolean => /^((?!chrome|android).)*safari/i.test(nav

export const isIOSChrome = (): boolean => /CriOS/.test(navigator.userAgent);

export const shareIcon: string = /Macintosh|iPhone|iPad|iPod/.test(navigator.userAgent) // macOS or iOS
? licon.ShareIos
: licon.ShareAndroid;
export const isApple: () => boolean = memoize<boolean>(
() => /Macintosh|iPhone|iPad|iPod/.test(navigator.userAgent), // macOS or iOS
);

export const shareIcon: () => string = () => (isApple() ? licon.ShareIos : licon.ShareAndroid);

export type Feature = 'wasm' | 'sharedMem' | 'simd';

Expand Down

0 comments on commit ab14fa8

Please sign in to comment.