Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const setMuseumMode = async museumMode => {
const setObj = [[APP_SETTINGS_KEYS.museumMode.key, boolToString(museumMode)]];
try {
await AsyncStorage.multiSet(setObj);
} catch (e) {
console.log(`Failed to save museumMode: ${e}`);
}
};
export const setLocaleAndRTLForReset = async localeObj => {
const setLocaleObj = Object.keys(localeObj).map(key => {
const value =
APP_SETTINGS_KEYS[key].type === APP_SETTINGS_TYPES.BOOL
? boolToString(localeObj[key])
: localeObj[key];
return [APP_SETTINGS_KEYS[key].key, value];
});
try {
await AsyncStorage.multiSet(setLocaleObj);
} catch (e) {
console.log(`Failed to save locale: ${e}`);
}
};
async function saveMultiValues(data) {
const mappedValues = values.map((v, i) => {
return [i, v];
});
try {
await AsyncStorage.multiSet(mappedValues);
return { success: true };
} catch (e) {
console.log("LOG_Async Storage access Failed", e);
return { error: e };
}
}
async (_username, password) => {
const json = await fetchWithAuth(
`/login?username=${_username}&password=${password}`,
);
await AsyncStorage.multiSet([
[STORAGE_KEYS.auth, json.auth],
[STORAGE_KEYS.username, _username],
[STORAGE_KEYS.secret, json.apisecret],
]);
setAuth(json.auth);
setUsername(_username);
setSecret(json.apisecret);
},
[fetchWithAuth],
return new Promise((resolve, reject) => {
if (keyValueWrites.length > 0) {
let updatedKeys = [];
for (let i = 0; i < keyValueWrites.length; i++) {
updatedKeys.push(keyValueWrites[i][0]);
}
AsyncStorage.multiSet(keyValueWrites)
.then(() => {
this._updateUserKeyCache(updatedKeys);
LOGd.store('Persistor: batch persisted', keyValueWrites);
})
.then( () => { resolve(); })
.catch((err) => { reject(err); })
}
else {
resolve();
}
})
}
multiSet: kvPairs => AsyncStorage.multiSet(kvPairs),
multiRemove: keys => AsyncStorage.multiRemove(keys),
multiSet: (items: string[][]) => {
return AsyncStorage.multiSet(items);
},
setItem: (key: string, value: string): Promise => {
save(key, value) {
if(!Array.isArray(key)) {
return AsyncStorage.setItem(key, JSON.stringify(value));
} else {
var pairs = key.map(function(pair) {
return [pair[0], JSON.stringify(pair[1])];
});
return AsyncStorage.multiSet(pairs);
}
},
const pairsToRemove = Object.entries(storageState)
.filter(([key, value]) => !hasValue(value));
await AsyncStorage.multiRemove(pairsToRemove.map((([key]) => storageKeys[key])));
const pairsToWrite = Object.entries(storageState)
.filter(([key, value]) => value !== null && value !== undefined);
if (pairsToWrite.length === 0) {
log.debug('Storage state is empty, no actuall write has been done');
return newState;
}
const pairs = pairsToWrite
.map(([key, value]) => [storageKeys[key], hasValue(value) ? JSON.stringify(value) : value]);
await AsyncStorage.multiSet(pairs);
return storageState;
}