Created
January 26, 2018 11:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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