UNPKG

algopat

Version:

Utility library for implementing common design patterns and algorithms

22 lines 746 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Singleton = void 0; class Singleton { constructor(factory) { if (Singleton._instance) { throw new Error(`${this.constructor.name} is a singleton class. Use instance()`); } Singleton._instance = factory.make(); } static instance(factory) { if (this._instance === null) { if (!factory) throw new Error(`${this.prototype.constructor.name} has not been initialized with a factory`); this._instance = factory.make(); } return this._instance; } } exports.Singleton = Singleton; Singleton._instance = null; //# sourceMappingURL=singleton.pattern.js.map