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

memoized-class-decorator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoized-class-decorator

Minimalistic memoization decorator

  • 1.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Memoized Decorator

A fork of memoized-decorator that takes class properties into consideration by attaching the memoization cache at the object level rather than class level.

Serializes arguments by .toString() or JSON.strinigify for objects literals & arrays. null & undefined safe.

Installation

npm install --save memoized-class-decorator

Usage

import memoize = require('memoized-class-decorator');

class Foo {

  constructor(private readonly num: number) { }

  @memoize
  public myMethod(add: number) {
    return this.num + add;
  }
}

const f1 = new Foo(5);

f1.myMethod(5);  //= 10 (method is invoked)
f1.myMethod(10); //= 15 (method is invoked)
f1.myMethod(5);  //= 10 (method is not invoked)

const f2 = new Foo(0);

f2.myMethod(5);  //= 5 (method is invoked, each object has it's own cache)

Note that if an object is passed to the method with an id property, the value of that propery will be used as the cache key. This is to reduce the time needed to serialize complex objects.

Keywords

FAQs

Package last updated on 08 Mar 2018

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