From 40705824e37f34f05c03bce5195963fa2f66ef47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Fri, 30 Aug 2019 13:50:24 +0200 Subject: [PATCH 1/2] fix: pass constructor options to parent This will make the KeyvLruManagedTtl parent aware of the options. --- src/KeyvLruManagedTtl.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/KeyvLruManagedTtl.js b/src/KeyvLruManagedTtl.js index 17e3758..5d2e459 100644 --- a/src/KeyvLruManagedTtl.js +++ b/src/KeyvLruManagedTtl.js @@ -26,9 +26,10 @@ class KeyvLruManagedTtl extends KeyvLru { max: number, notify?: boolean, ttl?: number, + expire?: number, } = { max: 500 } ) { - super(); + super(options); this.cache = lru(options.max, options.notify); } From 40937479f49c02533da321ff9440aac1574ada08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Fri, 30 Aug 2019 13:53:25 +0200 Subject: [PATCH 2/2] refactor: consolidate types --- src/KeyvLru.js | 16 ++++++++-------- src/KeyvLruManagedTtl.js | 10 ++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/KeyvLru.js b/src/KeyvLru.js index 0e84fd4..be61466 100644 --- a/src/KeyvLru.js +++ b/src/KeyvLru.js @@ -2,6 +2,13 @@ import type { MapInterface } from '../flow/types/MapInterface'; +export type KeyvLruOptions = { + max: number, + notify?: boolean, + ttl?: number, + expire?: number, +}; + const lru = require('tiny-lru'); const EventEmitter = require('events'); @@ -13,14 +20,7 @@ class KeyvLru extends EventEmitter implements MapInterface { cache: Object; defaultTtl: ?number; - constructor( - options: { - max: number, - notify?: boolean, - ttl?: number, - expire?: number, - } = { max: 500 } - ) { + constructor(options: KeyvLruOptions = { max: 500 }) { super(); this.defaultTtl = options.ttl; this.cache = lru( diff --git a/src/KeyvLruManagedTtl.js b/src/KeyvLruManagedTtl.js index 5d2e459..7d9f93e 100644 --- a/src/KeyvLruManagedTtl.js +++ b/src/KeyvLruManagedTtl.js @@ -1,6 +1,7 @@ // @flow import type { ExpirableItem } from '../flow/types/ExpirableItem'; +import type { KeyvLruOptions } from './KeyvLru'; const lru = require('tiny-lru'); const KeyvLru = require('./KeyvLru'); @@ -21,14 +22,7 @@ class KeyvLruManagedTtl extends KeyvLru { cache: Object; defaultTtl: ?number; - constructor( - options: { - max: number, - notify?: boolean, - ttl?: number, - expire?: number, - } = { max: 500 } - ) { + constructor(options: KeyvLruOptions = { max: 500 }) { super(options); this.cache = lru(options.max, options.notify); }