@dependable/debounce
v0.1.1
Published
Allowing debouncing @dependable/state subscribables
Downloads
25
Maintainers
Readme
@dependable/debounce
Debouncing @dependable/state subscribables.
Install
# npm
npm install --save @dependable/debounce
# yarn
yarn add @dependable/debounce
Usage
Debouncing an observable
You can create a debounced version of an observable to following way:
import { debounce } from "@dependable/debounce";
import { observable } from "@dependable/state";
const searchText = observable("");
const debouncedSearchText = debounce(searchText, 300);
Now all updates to searchText
will be debounced 300ms and cause a delayed update to debouncedSearchText
.
This is useful when you need to create instants search, where you only want to query the server after a delay.
Debouncing a computed
Similar to how you can debounce an observable, you can also debounce computeds:
import { debounce } from "@dependable/debounce";
import { observable, computed } from "@dependable/state";
const searchText = observable("");
const upperCaseSearchText = computed(() => searchText().toUpperCase());
const debouncedUpperCaseSearchText = debounce(upperCaseSearchText, 300);