wallpaperStorage.js 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import localForage from 'localforage';
  2. //import _ from 'lodash';
  3. const wpStore = localForage.createInstance({
  4. name: 'wallpaperStorage'
  5. });
  6. class WallpaperStorage {
  7. constructor() {
  8. this.cachedKeys = [];
  9. }
  10. async init() {
  11. this.cachedKeys = await wpStore.keys();
  12. }
  13. async getLength() {
  14. return await wpStore.length();
  15. }
  16. async setData(key, data) {
  17. await wpStore.setItem(key, data);
  18. this.cachedKeys = await wpStore.keys();
  19. }
  20. async getData(key) {
  21. return await wpStore.getItem(key);
  22. }
  23. async removeData(key) {
  24. await wpStore.removeItem(key);
  25. this.cachedKeys = await wpStore.keys();
  26. }
  27. async getKeys() {
  28. return await wpStore.keys();
  29. }
  30. keyExists(key) {//не асинхронная
  31. return this.cachedKeys.includes(key);
  32. }
  33. }
  34. export default new WallpaperStorage();