Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andreypopp/memoize-decorator

Memoize getters and methods to compute only once
https://github.com/andreypopp/memoize-decorator

Last synced: 23 days ago
JSON representation

Memoize getters and methods to compute only once

Awesome Lists containing this project

README

        

# memoize decorator

This is a method/getter decorator which is when applied to a method or a getter
memoizes the result of the first call and returns it on subsequent calls.

As decorators are a part of future ES7 standard they can only be used with
transpilers such as [Babel](http://babeljs.io).

Installation:

% npm install memoize-decorator

Example:

```js
import memoize from 'memoize-decorator'

class Component {

@memoize
get expensiveValue() {
console.log('heavy computations')
return 42
}
}

let component = new Component()
component.expensiveValue // prints 'heavy computations', returns 42
component.expensiveValue // just returns 42
```