@sendbird/uikit-react-native
Version:
Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
101 lines (100 loc) • 3.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _uikitUtils = require("@sendbird/uikit-utils");
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class InternalLocalCacheStorage {
constructor(storage) {
_defineProperty(this, "_mmkv", void 0);
_defineProperty(this, "_async", void 0);
_defineProperty(this, "clear", _uikitUtils.ASYNC_NOOP);
_defineProperty(this, "flushGetRequests", _uikitUtils.ASYNC_NOOP);
if ('getString' in storage) {
this._mmkv = storage;
} else {
this._async = storage;
}
}
async getAllKeys() {
if (this._mmkv) {
return this._mmkv.getAllKeys();
} else if (this._async) {
return this._async.getAllKeys();
} else {
return [];
}
}
async getItem(key) {
if (this._mmkv) {
return this._mmkv.getString(key) ?? null;
} else if (this._async) {
return this._async.getItem(key);
} else {
return null;
}
}
async removeItem(key) {
if (this._mmkv) {
this._mmkv.delete(key);
} else if (this._async) {
return this._async.removeItem(key);
}
}
async setItem(key, value) {
if (this._mmkv) {
this._mmkv.set(key, value);
} else if (this._async) {
return this._async.setItem(key, value);
}
}
async multiGet(keys) {
if (this._mmkv) {
return Promise.all(keys.map(async key => [key, await this.getItem(key)]));
} else if (this._async) {
var _this$_async;
if ((_this$_async = this._async) !== null && _this$_async !== void 0 && _this$_async.multiGet) {
return this._async.multiGet(keys);
} else {
return Promise.all(keys.map(async key => [key, await this.getItem(key)]));
}
} else {
return [];
}
}
async multiRemove(keys) {
if (this._mmkv) {
await Promise.all(keys.map(async key => this.removeItem(key)));
} else if (this._async) {
var _this$_async2;
if ((_this$_async2 = this._async) !== null && _this$_async2 !== void 0 && _this$_async2.multiRemove) {
await this._async.multiRemove(keys);
} else {
await Promise.all(keys.map(async key => this.removeItem(key)));
}
}
}
async multiSet(keyValuePairs) {
if (this._mmkv) {
await Promise.all(keyValuePairs.map(_ref => {
let [key, value] = _ref;
return this.setItem(key, value);
}));
} else if (this._async) {
var _this$_async3;
if ((_this$_async3 = this._async) !== null && _this$_async3 !== void 0 && _this$_async3.multiSet) {
await this._async.multiSet(keyValuePairs);
} else {
await Promise.all(keyValuePairs.map(_ref2 => {
let [key, value] = _ref2;
return this.setItem(key, value);
}));
}
}
}
}
exports.default = InternalLocalCacheStorage;
//# sourceMappingURL=InternalLocalCacheStorage.js.map