Memoize getters and methods to compute only once

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.


% npm install memoize-decorator


import memoize from 'memoize-decorator'

class Component {

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

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