Skip to content

Instantly share code, notes, and snippets.

@rodu
Created January 26, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodu/0d84dd5bf5bd9935274e5e6f3ab038be to your computer and use it in GitHub Desktop.
Save rodu/0d84dd5bf5bd9935274e5e6f3ab038be to your computer and use it in GitHub Desktop.
A sample decorator to create a delay on class methods or other functions
import { delay } from 'lodash';
const UI_DELAY = 250; // milliseconds
export function uidelay(wait = UI_DELAY) {
return function(target, method, descriptor, ...args) {
const original = descriptor.value;
return Object.assign(descriptor, {
value() {
delay(() => original.call(this), wait, ...args);
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment