File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ import _ from 'lodash' ;
2
+
3
+ function useDebouncedRef < T > ( initialValue : T , delay : number , immediate : boolean = false ) {
4
+ const state = ref ( initialValue ) ;
5
+ const debouncedRef = customRef ( ( track , trigger ) => ( {
6
+ get ( ) {
7
+ track ( ) ;
8
+ return state . value ;
9
+ } ,
10
+ set : _ . debounce (
11
+ ( value ) => {
12
+ state . value = value ;
13
+ trigger ( ) ;
14
+ } ,
15
+ delay ,
16
+ { leading : immediate } ,
17
+ ) ,
18
+ } ) ) ;
19
+ return debouncedRef ;
20
+ }
21
+ export default useDebouncedRef ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import emojiKeywords from 'emojilib';
4
4
import _ from ' lodash' ;
5
5
import type { EmojiInfo } from ' ./emoji.types' ;
6
6
import { useFuzzySearch } from ' @/composable/fuzzySearch' ;
7
+ import useDebouncedRef from ' @/composable/debouncedref' ;
7
8
8
9
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji .split (' ' ).map (unit => ` \\ u${unit .charCodeAt (0 ).toString (16 ).padStart (4 , ' 0' )}` ).join (' ' );
9
10
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji .codePointAt (0 ) ? ` 0x${emoji .codePointAt (0 )?.toString (16 )} ` : undefined ;
@@ -23,7 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
23
24
.map ((emojiInfos , group ) => ({ group , emojiInfos }))
24
25
.value ();
25
26
26
- const searchQuery = ref (' ' );
27
+ const searchQuery = useDebouncedRef (' ' , 500 );
27
28
28
29
const { searchResult } = useFuzzySearch ({
29
30
search: searchQuery ,
You can’t perform that action at this time.
0 commit comments