angular-persistence
Version:
A library to handle persistence for Angular 2 applications.
67 lines • 2.07 kB
JavaScript
import { SessionStorage } from './storage.session';
import { LocalStorage } from './storage.local';
import { ImmutableMemoryStorage } from './storage.immutable_memory';
import { MemoryStorage } from './storage.memory';
import { StorageType } from '../../constants/persistence.storage_type';
/**
* A factory used to retrieve Storage objects
*
* @export
* \@class StorageFactory
*
* @author Scott O'Bryan
* \@since 1.0
*/
export var StorageFactory = (function () {
function StorageFactory() {
this._storages = [];
}
/**
* Returns a new instance of the storage factory.
*
* \@static
* @return {?}
*/
StorageFactory.getStorage = function () {
return new StorageFactory();
};
/**
* Returns a singleton object of a specified type. Storage
* types are initialized lazily.
*
* @param {?} type
* @return {?}
*/
StorageFactory.prototype.of = function (type) {
var /** @type {?} */ storage = this._storages[type];
if (!storage) {
switch (type) {
case StorageType.MEMORY:
storage = new MemoryStorage();
this._storages[type] = storage;
break;
case StorageType.IMMUTABLE_MEMORY:
storage = new ImmutableMemoryStorage();
break;
case StorageType.LOCAL:
storage = new LocalStorage();
break;
case StorageType.SESSION:
storage = new SessionStorage();
break;
default:
}
if (!storage || !storage.available()) {
throw new Error('Storage type not available');
}
this._storages[type] = storage;
}
return storage;
};
return StorageFactory;
}());
function StorageFactory_tsickle_Closure_declarations() {
/** @type {?} */
StorageFactory.prototype._storages;
}
//# sourceMappingURL=storage.factory.js.map