miniapp-web-jsapi
Version:
JSAPI/View adapter for miniprogram running on the web
86 lines • 3.23 kB
JavaScript
import { asyncRun } from "../../../common";
import StorageImpl from './storage';
export function getStorage(options) {
asyncRun(function () {
try {
var _options$success;
var result = getStorageSync({
key: options.key
});
(_options$success = options.success) === null || _options$success === void 0 ? void 0 : _options$success.call(options, result);
} catch (e) {
var _options$fail;
(_options$fail = options.fail) === null || _options$fail === void 0 ? void 0 : _options$fail.call(options);
} finally {
var _options$complete;
(_options$complete = options.complete) === null || _options$complete === void 0 ? void 0 : _options$complete.call(options);
}
});
}
export function getStorageSync(options) {
var key = options.key;
return {
success: true,
key: key,
data: StorageImpl.getStorage(key)
};
}
export function setStorage(options) {
asyncRun(function () {
try {
var _options$success2;
setStorageSync({
key: options.key,
data: options.data
});
(_options$success2 = options.success) === null || _options$success2 === void 0 ? void 0 : _options$success2.call(options);
} catch (e) {
var _options$fail2;
(_options$fail2 = options.fail) === null || _options$fail2 === void 0 ? void 0 : _options$fail2.call(options);
} finally {
var _options$complete2;
(_options$complete2 = options.complete) === null || _options$complete2 === void 0 ? void 0 : _options$complete2.call(options);
}
});
}
export function setStorageSync(options) {
StorageImpl.setStorage(options.key, options.data);
}
export function removeStorage(options) {
asyncRun(function () {
try {
var _options$success3;
removeStorageSync({
key: options.key
});
(_options$success3 = options.success) === null || _options$success3 === void 0 ? void 0 : _options$success3.call(options);
} catch (e) {
var _options$fail3;
(_options$fail3 = options.fail) === null || _options$fail3 === void 0 ? void 0 : _options$fail3.call(options);
} finally {
var _options$complete3;
(_options$complete3 = options.complete) === null || _options$complete3 === void 0 ? void 0 : _options$complete3.call(options);
}
});
}
export function removeStorageSync(options) {
StorageImpl.removeStorage(options.key);
}
export function clearStorage(options) {
asyncRun(function () {
try {
var _options$success4;
clearStorageSync();
options === null || options === void 0 ? void 0 : (_options$success4 = options.success) === null || _options$success4 === void 0 ? void 0 : _options$success4.call(options);
} catch (e) {
var _options$fail4;
options === null || options === void 0 ? void 0 : (_options$fail4 = options.fail) === null || _options$fail4 === void 0 ? void 0 : _options$fail4.call(options);
} finally {
var _options$complete4;
options === null || options === void 0 ? void 0 : (_options$complete4 = options.complete) === null || _options$complete4 === void 0 ? void 0 : _options$complete4.call(options);
}
});
}
export function clearStorageSync() {
StorageImpl.clearStorage();
}