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
The config object to throttle and throttleTime behaves in an unexpected way regarding leading.
The documentation states that the config parameter "Defaults to { leading: true, trailing: false }" but if a config parameter is specified the default value for leading becomes false.
In other words, if someone wants to change the behaviour for trailing to true and therefore adds a config parameter { trailing: true } this also changes the behavior of leading to be false.
I was first tricked by this but then realised I have to specify both leading and trailing even if I just want to change the behavior of trailing. But then I got PR review comments on the updated code from two independent people that I did not have to specify leading: true since that is the default value.
So it seems like the current behaviour is quite unexpected since they also thought that default value for leading would not be affected by specifying trailing.
Expected behavior
I would expect that leading is set to the default value (true) but this code would cause leading: false:
throttle(1000,undefined,{trailing: true}
I expect the reproduction code to print the same as if I do not specify trailing, ie:
The text was updated successfully, but these errors were encountered:
tobiiasl
changed the title
Unexpected false default value for leading when only trailing is specified in config parameter
Unexpected false default value for leading when only trailing is specified in config parameter
Jan 11, 2023
Describe the bug
The config object to
throttle
andthrottleTime
behaves in an unexpected way regardingleading
.The documentation states that the config parameter "
Defaults to { leading: true, trailing: false }
" but if a config parameter is specified the default value forleading
becomes false.In other words, if someone wants to change the behaviour for
trailing
totrue
and therefore adds a config parameter{ trailing: true }
this also changes the behavior ofleading
to befalse
.I was first tricked by this but then realised I have to specify both
leading
andtrailing
even if I just want to change the behavior oftrailing
. But then I got PR review comments on the updated code from two independent people that I did not have to specifyleading: true
since that is the default value.So it seems like the current behaviour is quite unexpected since they also thought that default value for
leading
would not be affected by specifyingtrailing
.Expected behavior
I would expect that
leading
is set to the default value (true
) but this code would causeleading: false
:I expect the reproduction code to print the same as if I do not specify
trailing
, ie:but it prints
Reproduction code
Reproduction URL
https://stackblitz.com/edit/rxjs-wehnfb?file=index.ts
Version
7.5.5
Environment
No response
Additional context
I believe the last line in this code defines the current behavior:
The text was updated successfully, but these errors were encountered: