sunesimonsen / dependable-debounce

Allowing debouncing @dependable/state subscribables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Allowing debouncing @dependable/state subscribables

License:MIT License


Languages

Language:JavaScript 100.0%