DjDiablo, лично я весьма скептически отношусь к версии 2.0. Что касается 1.х.х, то она уже надоела
Надоело писать обертки вида (см. под спойлером) для обновления скопа.
'use strict';
let {identity} = angular;
export default ($window, $q) => {
const {localforage} = $window;
const __FORAGE = Symbol();
return class LocalForage {
/**
* @param {Object} options
* @param {String} options.name
* @param {String} options.storeName
* @see [url]https://github.com/mozilla/localForage/issues/245#issuecomment-56895736[/url]
* @see [url]http://mozilla.github.io/localForage/#config[/url]
*/
constructor(options) {
this[__FORAGE] = localforage.createInstance(options);
}
/**
* @see [url]http://mozilla.github.io/localForage/#getitem[/url]
* @param {String} key
* @returns {Promise}
*/
get(key) {
let deferred = $q.defer();
this[__FORAGE].getItem(key).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#setitem[/url]
* @param {String} key
* @param {*} value
* @returns {Promise}
*/
set(key, value) {
let deferred = $q.defer();
this[__FORAGE].setItem(key, value).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#removeitem[/url]
* @param {String} key
* @returns {Promise}
*/
remove(key) {
let deferred = $q.defer();
this[__FORAGE].removeItem(key).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#clear[/url]
* @returns {Promise}
*/
clear() {
let deferred = $q.defer();
this[__FORAGE].clear().then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#length[/url]
* @returns {Promise}
*/
length() {
let deferred = $q.defer();
this[__FORAGE].length().then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* [url]http://mozilla.github.io/localForage/#key[/url]
* @param {Number} index
* @returns {Promise}
*/
key(index) {
let deferred = $q.defer();
this[__FORAGE].key(index).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#iterate[/url]
* @param {Function} callback
* @returns {Promise}
*/
each(callback) {
let deferred = $q.defer();
this[__FORAGE].iterate(callback).then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @see [url]http://mozilla.github.io/localForage/#keys[/url]
* @returns {Promise}
*/
keys() {
let deferred = $q.defer();
this[__FORAGE].keys().then(deferred.resolve, deferred.reject);
return deferred.promise;
}
/**
* @returns {Promise}
*/
values() {
let stack = [];
let onEach = (value) => {
stack.push(value);
};
let onResolved = () => stack;
return this.each(onEach).then(onResolved, identity);
}
};
}
module.exports.$inject = [
'$window',
'$q'
];
Планирую на
vue.js переезжать.
Там все чисто и прозрачно в большинстве своем.
Нет провайдеров, сервисов, фабрик, констант и иже с ним.