You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As can be seen in the code below, taken from the source, there is no deferred execution. This is correct for a throttle function, but not for a debounce function, at least in the namesake project Lodash.
classDebounce(object):
"""Wrap a function in a debounce context."""def__init__(self, func, wait, max_wait=False):
self.func=funcself.wait=waitself.max_wait=max_waitself.last_result=None# Initialize last_* times to be prior to the wait periods so that func# is primed to be executed on first call.self.last_call=pyd.now() -self.waitself.last_execution=pyd.now() -max_waitifpyd.is_number(max_wait) elseNonedef__call__(self, *args, **kwargs):
""" Execute :attr:`func` if function hasn't been called witinin last :attr:`wait` milliseconds or in last :attr:`max_wait` milliseconds. Return results of last successful call. """present=pyd.now()
if (present-self.last_call) >=self.waitor (
self.max_waitand (present-self.last_execution) >=self.max_wait
):
self.last_result=self.func(*args, **kwargs)
self.last_execution=presentself.last_call=presentreturnself.last_result
The text was updated successfully, but these errors were encountered:
Expected Behaviour
When invoked, the debounced function is invoked after
wait
milliseconds.Current Behaviour
When invoked, the debounced function is invoked immediately, not after
wait
milliseconds.Example
Reason
As can be seen in the code below, taken from the source, there is no deferred execution. This is correct for a throttle function, but not for a debounce function, at least in the namesake project Lodash.
The text was updated successfully, but these errors were encountered: