Hakon Grotte
04/20/2022, 6:36 AMHakon Grotte
04/20/2022, 6:36 AM@JsModule("lodash/debounce")
@JsNonModule
external fun <K, V> debounce(functionToDebounce: (K) -> V, debounceMillis: Int): (K) -> V
, and my test function
debounce<Unit, Unit>({ console.log("debounced") }, 2000)
. The log statement never occurs. Thus I tried to change the functionToDebounce
parameter- and the return value type to dynamic
, and test without a lambda function as the first parameter:
debounce<Unit, Unit>( console.log("debounced") , 2000)
, which triggers the runtime error
Uncaught TypeError: Expected a function
debounce Lodash
, indicating to me that the import is sort of correct(?). Lodash source code snippet:
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
Does anyone have a clue as to why my initial test function does not log to the console? 🙂Big Chungus
04/20/2022, 10:28 AMHakon Grotte
04/20/2022, 11:01 AM* @since 0.1.0
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0]
* The number of milliseconds to delay; if omitted, `requestAnimationFrame` is
* used (if available).
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
function debounce(func, wait, options) {...}
Source: https://github.com/lodash/lodash/blob/master/debounce.jsBig Chungus
04/20/2022, 11:06 AMBig Chungus
04/20/2022, 11:08 AM@JsModule("lodash/debounce")
@JsNonModule
external fun <K, V> debounce(functionToDebounce: (K) -> V, debounceMillis: Int, options: dynamic = definedExternally): (K) -> V
debounce<Unit,Unit>({ console.log("debounced") }, 2000)()
Hakon Grotte
04/20/2022, 11:43 AMcompileKotlinJs:
No value passed for parameter 'p1'
inside the final function invocation. It expects generic parameter “K”, even when it is defined as “Unit”. If I set the return value to dynamic
it compiles and debounce works as expected.
Thank you for you help! 🙌
Do you have some idea on how to tweak the return value / function invocation to prevent usage of dynamic
return value?Big Chungus
04/20/2022, 11:47 AM@JsModule("lodash/debounce")
@JsNonModule
external fun <I, O, F: (I) -> O> debounce(functionToDebounce: F, debounceMillis: Int, options: dynamic = definedExternally): F
Big Chungus
04/20/2022, 11:48 AMBig Chungus
04/20/2022, 12:27 PMno
arguments as opposed to no arguments of significance
)
debounce<Nothing,Unit>({ console.log("debounced") }, 2000)()
rocketraman
04/20/2022, 12:54 PMHakon Grotte
04/20/2022, 3:20 PMrocketraman
04/20/2022, 3:24 PMHakon Grotte
04/20/2022, 3:28 PMturansky
04/20/2022, 3:58 PM@JsModule("lodash.debounce")