Skip to content

zwigglers/memoizee-decorator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

memoizee-decorator

ES7 function decorator wrapper for the memoizee library (https://github.com/medikoo/memoizee).

Based on memoize-decorator (https://github.com/andreypopp/memoize-decorator). Using memoizee enables support for functions with arguments.

Also passes through memoizee options. For functions with parameters with default values, you have to set the length option explicitly, or use the option { length: false }

Usage

import memoize from 'memoizee-decorator';

class Foo {
  @memoize
  get bar() {
    console.log('Complicated calculations...');
    return 42;
  }

  @memoize({length:1})
  someFunc(num=21) {
    console.log('Complicated calculations...');
    return num;
  }

}

Can be used either plain @memoize or with options @memoize({...options})

As with all decorators, you have to use a transpiler. Refer to https://github.com/andreypopp/autobind-decorator#autobind-decorator for prerequisites.

About

Memoize getters and methods to compute only once

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%