StorageController.default.js 945 B

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