MCPcopy
hub / github.com/sunnylqm/react-native-storage / constructor

Method constructor

storage.js:9–38  ·  view source on GitHub ↗
(options = {})

Source from the content-addressed store, hash-verified

7
8export default class Storage {
9 constructor(options = {}) {
10 this._SIZE = options.size || 1000; // maximum capacity
11 this.sync = options.sync || {}; // remote sync method
12 this.defaultExpires = options.defaultExpires !== undefined ?
13 options.defaultExpires : 1000 * 3600 * 24;
14 this.enableCache = options.enableCache !== false;
15 this._s = options.storageBackend || null;
16 this._innerVersion = 11;
17 this.cache = {};
18
19 if (this._s && this._s.setItem) {
20 try {
21 var promiseTest = this._s.setItem('__react_native_storage_test', 'test');
22 this.isPromise = !!(promiseTest && promiseTest.then);
23 }
24 catch (e) {
25 console.warn(e);
26 delete this._s;
27 throw e;
28 }
29 } else {
30 console.warn(`Data would be lost after reload cause there is no storageBackend specified!
31 \nEither use localStorage(for web) or AsyncStorage(for React Native) as a storageBackend.`)
32 }
33
34 this._mapPromise = this.getItem('map').then(map => {
35 this._m = this._checkMap(map && JSON.parse(map) || {});
36 // delete this._mapPromise;
37 });
38 }
39 getItem(key) {
40 return this._s
41 ?

Callers

nothing calls this directly

Calls 3

getItemMethod · 0.95
_checkMapMethod · 0.95
setItemMethod · 0.80

Tested by

no test coverage detected