StorageController.default.js 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. const memMap = {};
  14. const StorageController = {
  15. async: 0,
  16. getItem(path
  17. /*: string*/
  18. )
  19. /*: ?string*/
  20. {
  21. if (memMap.hasOwnProperty(path)) {
  22. return memMap[path];
  23. }
  24. return null;
  25. },
  26. setItem(path
  27. /*: string*/
  28. , value
  29. /*: string*/
  30. ) {
  31. memMap[path] = String(value);
  32. },
  33. removeItem(path
  34. /*: string*/
  35. ) {
  36. delete memMap[path];
  37. },
  38. clear() {
  39. for (const key in memMap) {
  40. if (memMap.hasOwnProperty(key)) {
  41. delete memMap[key];
  42. }
  43. }
  44. }
  45. };
  46. module.exports = StorageController;