StorageController.default.js 1.2 KB

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