123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- "use strict";
- var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
- /**
- * Copyright (c) 2015-present, Parse, LLC.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @flow
- */
- const LocalDatastoreController = {
- fromPinWithName(name
- /*: string*/
- )
- /*: Array<Object>*/
- {
- const values = wx.getStorageSync(name);
- if (!values) {
- return [];
- }
- return values;
- },
- pinWithName(name
- /*: string*/
- , value
- /*: any*/
- ) {
- try {
- wx.setStorageSync(name, value);
- } catch (e) {// Quota exceeded
- }
- },
- unPinWithName(name
- /*: string*/
- ) {
- wx.removeStorageSync(name);
- },
- getAllContents()
- /*: Object*/
- {
- const res = wx.getStorageInfoSync();
- const keys = res.keys;
- const LDS = {};
- for (const key of keys) {
- if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
- LDS[key] = wx.getStorageSync(key);
- }
- }
- return LDS;
- },
- getRawStorage()
- /*: Object*/
- {
- const res = wx.getStorageInfoSync();
- const keys = res.keys;
- const storage = {};
- for (const key of keys) {
- storage[key] = wx.getStorageSync(key);
- }
- return storage;
- },
- clear()
- /*: Promise*/
- {
- const res = wx.getStorageInfoSync();
- const keys = res.keys;
- const toRemove = [];
- for (const key of keys) {
- if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
- toRemove.push(key);
- }
- }
- const promises = toRemove.map(this.unPinWithName);
- return Promise.all(promises);
- }
- };
- module.exports = LocalDatastoreController;
|