11export function debounce ( func , wait , immediate ) {
2- let timeout , args , context , timestamp , result
2+ let timeout , args , context , timestamp , result ;
33
4- const later = function ( ) {
4+ const later = function ( ) {
55 // 据上一次触发时间间隔
6- const last = + new Date ( ) - timestamp
6+ const last = + new Date ( ) - timestamp ;
77
88 // 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
99 if ( last < wait && last > 0 ) {
10- timeout = setTimeout ( later , wait - last )
10+ timeout = setTimeout ( later , wait - last ) ;
1111 } else {
12- timeout = null
12+ timeout = null ;
1313 // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
1414 if ( ! immediate ) {
15- result = func . apply ( context , args )
16- if ( ! timeout ) context = args = null
15+ result = func . apply ( context , args ) ;
16+ if ( ! timeout ) context = args = null ;
1717 }
1818 }
19- }
19+ } ;
2020
21- return function ( ...args ) {
22- context = this
23- timestamp = + new Date ( )
24- const callNow = immediate && ! timeout
21+ return function ( ...args ) {
22+ context = this ;
23+ timestamp = + new Date ( ) ;
24+ const callNow = immediate && ! timeout ;
2525 // 如果延时不存在,重新设定延时
26- if ( ! timeout ) timeout = setTimeout ( later , wait )
26+ if ( ! timeout ) timeout = setTimeout ( later , wait ) ;
2727 if ( callNow ) {
28- result = func . apply ( context , args )
29- context = args = null
28+ result = func . apply ( context , args ) ;
29+ context = args = null ;
3030 }
3131
32- return result
32+ return result ;
33+ } ;
34+ }
35+ // 根据某个属性值从MenuList查找拥有该属性值的menuItem
36+ export function getMenuItemInMenuListByProperty ( menuList , key , value ) {
37+ let stack = [ ] ;
38+ stack = stack . concat ( menuList ) ;
39+ let res ;
40+ while ( stack . length ) {
41+ let cur = stack . shift ( ) ;
42+ if ( cur . children && cur . children . length > 0 ) {
43+ stack = cur . children . concat ( stack ) ;
44+ }
45+ if ( value === cur [ key ] ) {
46+ res = cur ;
47+ }
3348 }
34- }
49+ return res ;
50+ }
0 commit comments