Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

decko

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decko

A collection of the most useful property decorators.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is decko?

Decko is a collection of decorators for JavaScript/TypeScript that simplify common patterns such as binding methods to their instances, memoizing function results, and throttling or debouncing function calls.

What are decko's main functionalities?

Bind

The @bind decorator ensures that the method is always called with the correct 'this' context, even if it's extracted from the instance.

class MyClass {
  @bind
  myMethod() {
    console.log(this);
  }
}
const instance = new MyClass();
const method = instance.myMethod;
method(); // Logs the instance of MyClass

Memoize

The @memoize decorator caches the result of a function call and returns the cached result when the same inputs occur again, avoiding redundant computations.

class MyClass {
  @memoize
  computeExpensiveValue(input) {
    console.log('Computing...');
    return input * 2;
  }
}
const instance = new MyClass();
console.log(instance.computeExpensiveValue(2)); // Logs 'Computing...' and then 4
console.log(instance.computeExpensiveValue(2)); // Logs 4 without 'Computing...'

Debounce

The @debounce decorator ensures that the decorated function is only called once within the specified time frame, even if it's triggered multiple times.

class MyClass {
  @debounce(300)
  handleResize() {
    console.log('Resized!');
  }
}
const instance = new MyClass();
window.addEventListener('resize', () => instance.handleResize());

Throttle

The @throttle decorator ensures that the decorated function is called at most once within the specified time frame, even if it's triggered multiple times.

class MyClass {
  @throttle(300)
  handleScroll() {
    console.log('Scrolled!');
  }
}
const instance = new MyClass();
window.addEventListener('scroll', () => instance.handleScroll());

Other packages similar to decko

FAQs

Package last updated on 27 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc