Skip to content

A saga to get a debounced value from a channel without cancelling the previous taken item's task. Useful for when you need to incrementally save progress or updates (e.g. autosave).

License

Notifications You must be signed in to change notification settings

di-ng/redux-saga-debounced-channel

Repository files navigation

redux-saga-debounced-channel

Greenkeeper badge

A saga to get a debounced value from a channel without cancelling the previous taken item's task. This is useful for when you need to incrementally save progress or updates (e.g. autosave), because without it you won't be able to receive responses from API calls that were triggered during the debounce process.

Installation & Usage

npm install --save redux-saga-debounced-channel

Also install peerDependencies (if not already installed)

npm install --save redux-saga

Usage:

import getDebouncedValueFromChannel from 'redux-saga-debounced-channel';
import { channel, Channel, SagaIterator } from 'redux-saga';

function* mySaga(): SagaIterator {
  // any redux-saga channel can be used
  const saveActionChannel: Channel<Action> = yield call(channel);

  const debouncedSaveAction = yield getDebouncedValueFromChannel(
    saveActionChannel,
    500, // delay in ms
  );
};

Usage

getDebouncedValueFromChannel

A saga that returns the last item on the channel after a specified delay.

getDebouncedValueFromChannel<T = AnyAction>(
  actionChannel: Channel<T>,
  delayInMs: number,
): SagaIterator

actionChannel

A redux-saga channel configured to receive the actions that need to be debounced

delayInMs

The amount of milliseconds to debounce by

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

About

A saga to get a debounced value from a channel without cancelling the previous taken item's task. Useful for when you need to incrementally save progress or updates (e.g. autosave).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •