Merge pull request #176 from thornbill/remove-migration

Remove pre-mobx storage solution and related migration
This commit is contained in:
Anthony Lavado 2020-12-07 18:20:50 -05:00 committed by GitHub
commit 0ff6def8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 90 deletions

21
App.js
View File

@ -21,9 +21,7 @@ import PropTypes from 'prop-types';
import { useStores } from './hooks/useStores';
import Colors from './constants/Colors';
import StorageKeys from './constants/Storage';
import AppNavigator from './navigation/AppNavigator';
import CachingStorage from './utils/CachingStorage';
import Theme from './utils/Theme';
// Import i18n configuration
@ -38,24 +36,7 @@ const App = observer(({ skipLoadingScreen }) => {
});
const hydrateStores = async () => {
// Migrate servers and settings
// TODO: Remove this for next release
const servers = await CachingStorage.getInstance().getItem(StorageKeys.Servers);
if (servers) {
const activeServer = await CachingStorage.getInstance().getItem(StorageKeys.ActiveServer) || 0;
// Initialize the store with the existing servers and settings
await trunk.init({
serverStore: { servers },
settingStore: { activeServer }
});
// Remove old data values
AsyncStorage.multiRemove(Object.values(StorageKeys));
} else {
// No servers saved in the old method, initialize normally
await trunk.init();
}
await trunk.init();
rootStore.storeLoaded = true;
};

View File

@ -1,11 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
const prefix = 'org.jellyfin.expo';
export default {
ActiveServer: `${prefix}:ActiveServer`,
Servers: `${prefix}:Servers`
};

View File

@ -1,59 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { AsyncStorage } from 'react-native';
/**
* AsyncStorage wrapper with in memory caching
* @deprecated
*/
export default class CachingStorage {
static instance = null;
cache = new Map();
static getInstance() {
if (this.instance === null) {
console.debug('CachingStorage: Initializing new instance');
this.instance = new CachingStorage();
} else {
console.debug('CachingStorage: Using existing instance');
}
return this.instance;
}
async getItem(key) {
// Throw an error if no key is provided
if (!key) {
throw new Error('No key specified for `getItem()`');
}
// Return cached value if present
if (this.cache.has(key)) {
console.debug(`CachingStorage: Returning value from cache for ${key}`);
return this.cache.get(key);
}
// Get the item from device storage
console.debug(`CachingStorage: Loading value from device storage for ${key}`);
let item = await AsyncStorage.getItem(key);
if (item !== null) {
item = JSON.parse(item);
this.cache.set(key, item);
}
return item;
}
async setItem(key, item = '') {
// Throw an error if no key is provided
if (!key) {
throw new Error('No key specified for `setItem()`');
}
console.debug(`CachingStorage: Saving value to device storage for ${key}`);
await AsyncStorage.setItem(key, JSON.stringify(item));
this.cache.set(key, item);
}
}