https://github.com/NetanelBasal/helpful-decorators
Helpful decorators for typescript projects
https://github.com/NetanelBasal/helpful-decorators
debounce decorators measure once settimeout throttle typscript
Last synced: 3 months ago
JSON representation
Helpful decorators for typescript projects
- Host: GitHub
- URL: https://github.com/NetanelBasal/helpful-decorators
- Owner: NetanelBasal
- License: mit
- Created: 2017-09-16T18:39:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T17:48:45.000Z (over 2 years ago)
- Last Synced: 2025-03-25T10:09:33.545Z (3 months ago)
- Topics: debounce, decorators, measure, once, settimeout, throttle, typscript
- Language: TypeScript
- Homepage: https://netbasal.com/create-and-test-decorators-in-javascript-85e8d5cf879c
- Size: 1.85 MB
- Stars: 463
- Watchers: 8
- Forks: 50
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[]()
[](https://travis-ci.org/NetanelBasal/helpful-decorators)
[](http://commitizen.github.io/cz-cli/)
[](https://github.com/semantic-release/semantic-release)
[](https://github.com/sindresorhus/awesome)# Helpful Decorators For Typescript Projects
## Installation
```js
npm install helpful-decorators
yarn add helpful-decorators
```## Usage
`delay` - Add `setTimeout` functionality to the method```js
import { delay } from 'helpful-decorators';class Test {
@delay(1000)
method() {
// ...
}
}
````debounce` - Add `debounce` functionality to the method ([options](https://lodash.com/docs/4.17.4#debounce))
```js
import { debounce } from 'helpful-decorators';class Test {
@debounce(1000, options)
method() {
// ...
}
}
````throttle` - Add `throttle` functionality to the method ([options](https://lodash.com/docs/4.17.4#throttle))
```js
import { throttle } from 'helpful-decorators';class Test {
@throttle(1000, options)
method() {
// ...
}
}
````once` - Add `once` functionality to the method
```js
import { once } from 'helpful-decorators';class Test {
@once
method() {
// This will run only once
}
}
````measure` - measure time taken by a function to execute
```js
import { measure } from 'helpful-decorators';class Test {
@measure
doSomething() {
// Call to doSomething took 0.35 milliseconds.
}@measure
async doSomethingHello(){
// Call to doSomethingHello took 0.35 milliseconds.
}
}
````Mixin` - this pattern is used to achieve multiple inheritance
```js
import { Mixin } from 'helpful-decorators';@Mixin([Disposable, Activatable])
class Test {
}
````memo` - memoizes the result of the function
```js
import { memo } from 'helpful-decorators';class Test {
@memo()
method() {
...memoized
}
}
````bind` - automatically bind methods to class instances
```js
import { bind } from 'helpful-decorators';@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor() {
document.body.addEventListener('click', this.onClick);
}@bind
onClick($event) {
console.log($event);
}
}
````SortBy` - sort an array by a specific property in individual elements or non-object items (By default, it sorts by `type === 'string'` and `isDescending === true`)
```js
import { SortBy } from 'helpful-decorators';class Test {
@SortBy('name', {
isDescending: false,
type: 'string'
})
names = [ { name: 'b' }, { name: 'a' }, { name: 'c' } ];@SortBy('', {
isDescending: true,
type: 'date'
})
dates = [ '2020-06-17', '2020-06-16', '2020-06-20', '2020-06-10' ];@SortBy('', {
isDescending: false,
type: 'number'
})
numbers = [ 6, 3, 4, 1 ];
}
```
License
----MIT