@dependable/debounce

0.1.1 • Public • Published

@dependable/debounce

Checks Bundle Size

Debouncing @dependable/state subscribables.

API documentation

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);

Package Sidebar

Install

npm i @dependable/debounce

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

10.8 kB

Total Files

10

Last publish

Collaborators

  • sunesimonsen