const debounce = ( fn , ms ? , immediate ? ) : Function => { let timeoutId ; return function ( this , ... args ) { const callNow = immediate && ! ms ; const next = ( ) => fn . apply ( this , args ) ; clearTimeout ( timeoutId ) ; timeoutId = setTimeout ( next , ms ) ; if ( callNow ) next ( ) ; } ; } ; export default debounce ;