Debounce your lambdas.
- What is debouncing?
- Problems to solve
- Reasons to use
- Installation
- What to use
- Migration
- 💡Examples
- License
In programming, "debouncing" refers to a technique used to prevent multiple triggering of an event or action due to rapid or repeated signals. Specifically, it is a process of filtering out unwanted, extraneous signals or noise from an input signal that can result in multiple events being triggered when only one is desired.
More here: article
- Prevent multiple clicks on a button from triggering the same action multiple times.
- Delay the processing of text field input until the user has finished typing, to improve performance and prevent unwanted intermediate results, like in search queries.
- Filter out noise and ensure that only valid sensor readings are used in decision-making processes.
- Convenient to use.
- Small source code size.
- 100% documented.
- Covered in unit tests.
Using Gradle Kotlin DSL:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.mmolosay:debounce:VERSION")
}
You can find the most recent version at the top of this file in Maven badge.
The centerpieces of this library are two functions:
The main difference between them is the moment when debouncing timeout starts.
For debounced()
timeout starts right after an execution of the action.
It suits for cases without coroutines or other indefinitely long operations.
For DebounceStateIdentity.debounce()
it is you who decide when to start a release timeout.
It's a right choice for actions which launch coroutines or contain other indefinitely long operations.
For examples of use see Examples section down below.
Some versions contain breaking changes. Check releases page for migration guide.
Examples can be found here.
Copyright 2023 Mikhail Malasai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.