Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Testing dynamic import name
Browse files Browse the repository at this point in the history
  • Loading branch information
dilan-dio4 committed Jun 1, 2021
1 parent 7df74f0 commit 494be73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -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",
Expand Down
11 changes: 8 additions & 3 deletions src/cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit 494be73

Please sign in to comment.