StorageController.default.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. /**
  3. * Copyright (c) 2015-present, Parse, LLC.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree. An additional grant
  8. * of patent rights can be found in the PATENTS file in the same directory.
  9. *
  10. * @flow
  11. * @private
  12. */
  13. // When there is no native storage interface, we default to an in-memory map
  14. const memMap = {};
  15. const StorageController = {
  16. async: 0,
  17. getItem(path
  18. /*: string*/
  19. )
  20. /*: ?string*/
  21. {
  22. if (memMap.hasOwnProperty(path)) {
  23. return memMap[path];
  24. }
  25. return null;
  26. },
  27. setItem(path
  28. /*: string*/
  29. , value
  30. /*: string*/
  31. ) {
  32. memMap[path] = String(value);
  33. },
  34. removeItem(path
  35. /*: string*/
  36. ) {
  37. delete memMap[path];
  38. },
  39. getAllKeys() {
  40. return Object.keys(memMap);
  41. },
  42. clear() {
  43. for (const key in memMap) {
  44. if (memMap.hasOwnProperty(key)) {
  45. delete memMap[key];
  46. }
  47. }
  48. }
  49. };
  50. module.exports = StorageController;