Home

Awesome

mobx-autorun-async-immediate NPM version Build Status Dependency Status Coverage percentage

Mobx debounced autorun function with immediate synchronous first call

Why use this?

If you need to run some heavy action (such as data fetching from server) when your observables change, you usually want to debounce your action. But you probably need the first run of your action to be synchronous (so the first fetching starts right away).

Why not use autorunAsync?

Mobx has autorunAsync, but it may not suit you for the following reasons:

Installation

$ npm install --save mobx-autorun-async-immediate

Usage

const autorunAsyncImmediate = require('mobx-autorun-async-immediate');
const scope = {};
const delay = 100;

const dispose = autorunAsyncImmediate(() => {
  // send request to fetch data from server
}, delay, scope);

// request is already sent here

License

MIT © dettier