StorageController.default.js 695 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. /**
  3. * @flow
  4. * @private
  5. */
  6. // When there is no native storage interface, we default to an in-memory map
  7. const memMap = {};
  8. const StorageController = {
  9. async: 0,
  10. getItem(path /*: string*/) /*: ?string*/{
  11. if (memMap.hasOwnProperty(path)) {
  12. return memMap[path];
  13. }
  14. return null;
  15. },
  16. setItem(path /*: string*/, value /*: string*/) {
  17. memMap[path] = String(value);
  18. },
  19. removeItem(path /*: string*/) {
  20. delete memMap[path];
  21. },
  22. getAllKeys() {
  23. return Object.keys(memMap);
  24. },
  25. clear() {
  26. for (const key in memMap) {
  27. if (memMap.hasOwnProperty(key)) {
  28. delete memMap[key];
  29. }
  30. }
  31. }
  32. };
  33. module.exports = StorageController;