StorageController.default.js 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. */
  12. // When there is no native storage interface, we default to an in-memory map
  13. var memMap = {};
  14. var StorageController = {
  15. async: 0,
  16. getItem: function (path
  17. /*: string*/
  18. )
  19. /*: ?string*/
  20. {
  21. if (memMap.hasOwnProperty(path)) {
  22. return memMap[path];
  23. }
  24. return null;
  25. },
  26. setItem: function (path
  27. /*: string*/
  28. , value
  29. /*: string*/
  30. ) {
  31. memMap[path] = String(value);
  32. },
  33. removeItem: function (path
  34. /*: string*/
  35. ) {
  36. delete memMap[path];
  37. },
  38. clear: function () {
  39. for (var key in memMap) {
  40. if (memMap.hasOwnProperty(key)) {
  41. delete memMap[key];
  42. }
  43. }
  44. }
  45. };
  46. module.exports = StorageController;