问题描述
对于我们的 ReactNative 应用程序,我们通过使用内部存储来消除加载时间。
最初来自 redux 存储的数据可以立即呈现,同时进行 api 调用以更新数据。在进行 api 调用后,最新的数据存储在 store.dispatch
中。
一切在 Android 和模拟器上运行良好,但在 iPhone X 上,当 store.dispatch 被调用时,应用程序冻结。删除调度“解决”了问题。
可能是什么问题?我们应该尝试其他存储引擎吗?
编辑: 我根据我们的编码创建了一个基本的 redux 应用程序:https://snack.expo.io/@adriaandebolle/react-native---redux-store。使用 Expo 客户端可以在 iPhone 上正常工作。因此无法重现该问题...
我们的 store.js 文件:
import {createStore,compose,applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import {persistCombineReducers,persistStore} from 'redux-persist';
import AsyncStorage from '@react-native-community/async-storage';
import {encryptTransform} from 'redux-persist-transform-encrypt';
const encryptor = encryptTransform({
secretKey: '******',onError: function (error) {
// Handle the error.
console.log(error);
},});
const config = {
key: 'primary',storage: AsyncStorage,transforms: [encryptor],};
import {reducer as servicesReducer} from 'app/services/reducer';
const appReducer = persistCombineReducers(config,{
services: servicesReducer,});
const enhancer = compose(applyMiddleware(thunk));
const store = createStore(appReducer,enhancer);
const persistor = persistStore(store);
export {store,persistor};
依赖包.json
{
"dependencies": {
"npm": "^6.14.8","react": "16.13.1","react-native": "0.63.4","react-navigation": "^4.0.10","react-navigation-stack": "^1.9.4","react-redux": "^7.2.2","redux": "^4.0.5","redux-persist": "^6.0.0","redux-persist-transform-encrypt": "^3.0.1","redux-thunk": "^2.3.0","remote-redux-devtools": "^0.5.16",},}
解决方法
这不是操作系统问题,而是我似乎存储的数据量。 AsyncStorage 有一个大小限制,有些帐户超过了这个限制。一些警告可能很有趣,或者是找出哪个减速器导致达到限制的方法。
使用 arr.splice()
大大减少了存储数组的大小。一切正常。但是很高兴知道我们在“安全区”中的情况如何。