Skip to content

Commit

Permalink
feat(decorators): replace timeout with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBasal committed Nov 17, 2017
1 parent d77548e commit fa09ed6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ yarn add helpful-decorators
```

## Usage
`timeout` - Add `setTimeout` functionality to the method
`delay` - Add `setTimeout` functionality to the method
```ts
import { timeout } from 'helpful-decorators';
import { delay } from 'helpful-decorators';

class Test {
@timeout(1000)
@delay(1000)
method() {
// ...
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class Test {

### Roadmap

- ~~timeout~~
- ~~delay~~
- ~~debounce~~
- ~~throttle~~
- ~~once~~
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "helpful-decorators",
"version": "1.4.1",
"version": "1.5.0",
"description": "Helpful decorators for typescript projects",
"main": "dist/index.js",
"typings": "./dist/index.d.ts",
Expand Down Expand Up @@ -55,7 +55,8 @@
"dependencies": {
"conventional-changelog-cli": "^1.3.3",
"lodash.debounce": "^4.0.8",
"lodash.delay": "^4.1.1",
"lodash.once": "^4.1.1",
"lodash.throttle": "^4.1.1"
}
}
}
14 changes: 14 additions & 0 deletions src/delay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as delayFn from 'lodash.once';

/**
*
* @param wait
* @param options
*/
export function delay( wait : number = 0, args ) {
return function ( target : any, propertyKey : string, descriptor : PropertyDescriptor ) {
const originalMethod = descriptor.value;
descriptor.value = delayFn(originalMethod, wait, args);
return descriptor;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { measure } from './measure';
export { timeout } from './timeout';
export { delay } from './delay';
export { debounce } from './debounce';
export { throttle } from './throttle';
export { once } from './once';
Expand Down
2 changes: 1 addition & 1 deletion src/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
*
* @deprecated since version 1.5.0
* @param milliseconds
* @returns {(target:any, propertyKey:string, descriptor:PropertyDescriptor)=>PropertyDescriptor}
*/
Expand Down

0 comments on commit fa09ed6

Please sign in to comment.