StorageController.weapp.js 882 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. * @private
  12. */
  13. const StorageController = {
  14. async: 0,
  15. getItem(path
  16. /*: string*/
  17. )
  18. /*: ?string*/
  19. {
  20. return wx.getStorageSync(path);
  21. },
  22. setItem(path
  23. /*: string*/
  24. , value
  25. /*: string*/
  26. ) {
  27. try {
  28. wx.setStorageSync(path, value);
  29. } catch (e) {// Quota exceeded
  30. }
  31. },
  32. removeItem(path
  33. /*: string*/
  34. ) {
  35. wx.removeStorageSync(path);
  36. },
  37. getAllKeys() {
  38. const res = wx.getStorageInfoSync();
  39. return res.keys;
  40. },
  41. clear() {
  42. wx.clearStorageSync();
  43. }
  44. };
  45. module.exports = StorageController;