Browse Source

Pass instance of Keyv ee to storage adapters for error handling

emp
Luke Childs 7 years ago
committed by Jytesh
parent
commit
3d2b5c40cf
  1. 8
      packages/keyv/src/index.js

8
packages/keyv/src/index.js

@ -1,5 +1,7 @@
'use strict';
const EventEmitter = require('events').EventEmitter;
const loadStore = opts => {
const adapters = {
redis: 'keyv-redis',
@ -17,8 +19,9 @@ const loadStore = opts => {
return new Map();
};
class Keyv {
class Keyv extends EventEmitter {
constructor(uri, opts) {
super();
this.opts = Object.assign(
{},
(typeof uri === 'string') ? { uri } : uri,
@ -26,7 +29,8 @@ class Keyv {
);
if (!this.opts.store) {
this.opts.store = loadStore(this.opts);
const adapterOpts = Object.assign({ keyv: this }, this.opts);
this.opts.store = loadStore(adapterOpts);
}
}

Loading…
Cancel
Save