1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = void 0;
|
5 |
|
6 | var _reactNative = require("react-native");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var MEMORY_KEY_PREFIX = '@MemoryStorage:';
|
25 | var dataMemory = {};
|
26 |
|
27 |
|
28 | var MemoryStorage = function () {
|
29 | function MemoryStorage() {}
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | MemoryStorage.setItem = function setItem(key, value) {
|
38 | _reactNative.AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
|
39 |
|
40 | dataMemory[key] = value;
|
41 | return dataMemory[key];
|
42 | }
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | ;
|
50 |
|
51 | MemoryStorage.getItem = function getItem(key) {
|
52 | return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined;
|
53 | }
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | ;
|
60 |
|
61 | MemoryStorage.removeItem = function removeItem(key) {
|
62 | _reactNative.AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
|
63 |
|
64 | return delete dataMemory[key];
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 | ;
|
71 |
|
72 | MemoryStorage.clear = function clear() {
|
73 | dataMemory = {};
|
74 | return dataMemory;
|
75 | }
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 | ;
|
82 |
|
83 | MemoryStorage.sync = function sync(callback) {
|
84 | _reactNative.AsyncStorage.getAllKeys(function (errKeys, keys) {
|
85 | if (errKeys) return callback(errKeys, null);
|
86 | var memoryKeys = keys.filter(function (key) {
|
87 | return key.startsWith(MEMORY_KEY_PREFIX);
|
88 | });
|
89 |
|
90 | _reactNative.AsyncStorage.multiGet(memoryKeys, function (err, stores) {
|
91 | if (err) return callback(err, null);
|
92 | stores.map(function (result, index, store) {
|
93 | var key = store[index][0];
|
94 | var value = store[index][1];
|
95 | var memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
|
96 | dataMemory[memoryKey] = value;
|
97 | return undefined;
|
98 | });
|
99 | callback(null, 'SUCCESS');
|
100 | return undefined;
|
101 | });
|
102 |
|
103 | return undefined;
|
104 | });
|
105 | };
|
106 |
|
107 | return MemoryStorage;
|
108 | }();
|
109 |
|
110 |
|
111 |
|
112 | var StorageHelper = function () {
|
113 | |
114 |
|
115 |
|
116 |
|
117 | function StorageHelper() {
|
118 | this.storageWindow = MemoryStorage;
|
119 | }
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | var _proto = StorageHelper.prototype;
|
127 |
|
128 | _proto.getStorage = function getStorage() {
|
129 | return this.storageWindow;
|
130 | };
|
131 |
|
132 | return StorageHelper;
|
133 | }();
|
134 |
|
135 | exports["default"] = StorageHelper; |
\ | No newline at end of file |