From 494be73c4e74ae51fad6e4d985d5dedc5c5e8125 Mon Sep 17 00:00:00 2001 From: Dilan Date: Tue, 1 Jun 2021 10:46:39 -0400 Subject: [PATCH] Testing dynamic import name --- package.json | 13 +++++-------- src/cache.tsx | 11 ++++++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 9bc9fa7..fc6fb8b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "scripts": { "build": "npm run clean && npm run microbundle && npm run fixDist", "prepare": "npm run clean && npm run microbundle && npm run fixDist", - "microbundle": "microbundle build --jsx React.createElement --external react,react-native --no-compress --format modern,cjs", + "microbundle": "microbundle build --jsx React.createElement --external react --no-compress --format modern,cjs", "genDocs": "typedoc", "clean": "shx rm -rf dist", "fixDist": "shx cp -r dist/src/ui/Auth/. dist/ui/Auth && shx rm -rf dist/src/", @@ -26,9 +26,8 @@ }, "devDependencies": { "@types/node": "^12.12.38", - "@types/react": "17.0.1", - "@types/react-dom": "17.0.1", - "@types/react-native": "0.64.1", + "@types/react": "^17.0.1", + "@types/react-dom": "^17.0.1", "@types/styled-components": "^5.1.9", "@typescript-eslint/eslint-plugin": "^2.26.0", "@typescript-eslint/parser": "^2.26.0", @@ -42,9 +41,8 @@ "eslint-plugin-react": "^7.17.0", "eslint-plugin-standard": "^4.0.1", "microbundle": "^0.13.1", - "react": "17.0.1", - "react-dom": "17.0.1", - "react-native": "0.64.1", + "react": "^17.0.1", + "react-dom": "^17.0.1", "shx": "^0.3.3", "typedoc": "^0.20.36", "typescript": "^3.7.5" @@ -54,7 +52,6 @@ "scripts" ], "dependencies": { - "@react-native-async-storage/async-storage": "^1.15.5", "easybasejs": "4.2.13", "easyqb": "^1.0.20", "fast-deep-equal": "^3.1.3", diff --git a/src/cache.tsx b/src/cache.tsx index 649a358..c74c39a 100644 --- a/src/cache.tsx +++ b/src/cache.tsx @@ -5,9 +5,14 @@ import Storage from 'react-native-storage'; let storage: Storage; if ((typeof navigator !== 'undefined' && navigator.product === 'ReactNative')) { - import('@react-native-async-storage/async-storage').then(AsyncStorage => { - storage = new Storage({ storageBackend: AsyncStorage.default }); - }) + const _import_name = 'react-native'; + try { + import(_import_name).then(RN => { + storage = new Storage({ storageBackend: RN.AsyncStorage }); + }) + } catch (error) { + console.error('No AsyncStorage detected') + } } else { storage = new Storage({ storageBackend: window.localStorage }); }