rats-search/src/app/singleton.js
Alexey Kasyanchuk fd4ba2c392 fix eslint
2018-06-18 00:06:28 +03:00

30 lines
554 B
JavaScript

export default (Superclass) => {
let instance;
return class Singleton extends Superclass {
constructor(props) {
super(props)
if (instance) {
instance.props = props
return instance;
}
instance = this;
}
static instance() {
if (instance) {
return instance;
} else {
return new Singleton();
}
}
static do(key, ...params) {
if ( typeof this.instance()[key] === 'function') {
return this.instance()[key](...params);
} else {
return this.instance()[key];
}
}
}
}