Files
pezkuwi-ui/packages/exampleReactNative/nodeGlobalsShim.js
T
Cameron Franz b3e9b70341 react-native example app port (#223)
* add readme

* react-native example app

* update readme

* add ios-cli dep

* revert package.json change

* update readme

* update readme

* don't auto launch metro

* add react native scripts

* nohoist @react-native-community/**

* update readme

* undo wrong README change

* remove react-native root dep

* copyright headers

* semi-style

* add default gitignore

* finish linting

* remove test for now

* fix typescript errors

* fix linting

* update scripts

* update deps and version

* update readme

* remove accidental dep

* update readme

* bump deps

* update yarn.lock

* actually update yarn.lock

* fix yarn.lock conflicts by updating exampleReactNative deps
2019-10-10 21:22:21 +02:00

46 lines
1.1 KiB
JavaScript

// Copyright 2017-2019 @polkadot/example-react authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/* eslint-disable no-global-assign */
import AsyncStorage from '@react-native-community/async-storage';
class Storage {
constructor () {
this.dataMap = new Map();
this.loading = true;
}
init = async () => {
const keys = await AsyncStorage.getAllKeys();
const data = await AsyncStorage.multiGet(keys);
data.forEach(this.saveItem.bind(this));
this.loading = false;
return [...data];
}
getItem = key => {
return this.dataMap.get(key);
}
setItem = (key, value) => {
this.dataMap.set(key, value);
return AsyncStorage.setItem(key, value);
}
remove = key => {
this.dataMap.delete(key);
return AsyncStorage.removeItem(key);
}
saveItem = item => {
this.dataMap.set(item[0], item[1]);
}
}
// Set global process variable expected by some classes.
global.process = require('process');
global.navigator.userAgent = '';
window = { location: { host: '' } };
global.localStorage = new Storage();