File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 105105 "classnames" : " ^2.5.1" ,
106106 "lodash.isequal" : " ^4.5.0" ,
107107 "lodash.kebabcase" : " ^4.1.1" ,
108- "react-transition-group" : " ^4.4.5"
108+ "react-transition-group" : " ^4.4.5" ,
109+ "quick-lru" : " ^4.0.1"
109110 },
110111 "devDependencies" : {
111112 "@babel/core" : " ^7.23.9" ,
Original file line number Diff line number Diff line change 11import { createSelectorQuery } from '@tarojs/taro'
2+ import QuickLRU from 'quick-lru'
23import { getRect , inBrowser } from './use-client-rect'
34
5+ const lru = new QuickLRU ( { maxSize : 10 } )
6+
47export interface Rect {
58 dataset : Record < string , any >
69 id : string
@@ -30,10 +33,16 @@ export const getRectByTaro = async (element: any): Promise<Rect> => {
3033 }
3134 // 小程序下的逻辑
3235 return new Promise ( ( resolve , reject ) => {
36+ if ( lru . has ( element ) ) {
37+ resolve ( lru . get ( element ) as Rect )
38+ }
3339 createSelectorQuery ( )
3440 . select ( `#${ element . uid } ` )
3541 . boundingClientRect ( )
3642 . exec ( ( [ rects ] ) => {
43+ if ( rects ) {
44+ lru . set ( element , rects )
45+ }
3746 resolve ( rects )
3847 } )
3948 } )
You can’t perform that action at this time.
0 commit comments