LocalDatastoreController.default.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
  3. /**
  4. * Copyright (c) 2015-present, Parse, LLC.
  5. * All rights reserved.
  6. *
  7. * This source code is licensed under the BSD-style license found in the
  8. * LICENSE file in the root directory of this source tree. An additional grant
  9. * of patent rights can be found in the PATENTS file in the same directory.
  10. *
  11. * @flow
  12. */
  13. const memMap = {};
  14. const LocalDatastoreController = {
  15. fromPinWithName(name
  16. /*: string*/
  17. )
  18. /*: Array<Object>*/
  19. {
  20. if (!memMap.hasOwnProperty(name)) {
  21. return [];
  22. }
  23. const objects = JSON.parse(memMap[name]);
  24. return objects;
  25. },
  26. pinWithName(name
  27. /*: string*/
  28. , value
  29. /*: any*/
  30. ) {
  31. const values = JSON.stringify(value);
  32. memMap[name] = values;
  33. },
  34. unPinWithName(name
  35. /*: string*/
  36. ) {
  37. delete memMap[name];
  38. },
  39. getAllContents() {
  40. const LDS = {};
  41. for (const key in memMap) {
  42. if (memMap.hasOwnProperty(key) && (0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
  43. LDS[key] = JSON.parse(memMap[key]);
  44. }
  45. }
  46. return LDS;
  47. },
  48. getRawStorage() {
  49. return memMap;
  50. },
  51. clear() {
  52. for (const key in memMap) {
  53. if (memMap.hasOwnProperty(key) && (0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
  54. delete memMap[key];
  55. }
  56. }
  57. }
  58. };
  59. module.exports = LocalDatastoreController;