Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving files and folders a little #4

Merged
merged 4 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/App-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'react-native';
import React from 'react';
import App from '../js/App';
import App from '../src/App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
Expand Down
16 changes: 8 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const webpack = {
presets: [require('@babel/preset-react')],
plugins: [['react-native-web', {commonjs: true}]],
presets: ['@babel/preset-react', '@babel/preset-env'],
plugins: [['react-native-web', {commonjs: true}]],
};

const metro = {
presets: [require('metro-react-native-babel-preset')],
plugins: [],
presets: [require('metro-react-native-babel-preset')],
plugins: [],
};

module.exports = ({caller}) => {
// For `react-native` (iOS/Android) caller will be "metro"
// For `webpack` (Web) caller will be "@babel-loader"
const runningIn = caller(({name}) => name);
return runningIn === 'metro' ? metro : webpack;
// For `react-native` (iOS/Android) caller will be "metro"
// For `webpack` (Web) caller will be "@babel-loader"
const runningIn = caller(({name}) => name);
return runningIn === 'metro' ? metro : webpack;
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { AppRegistry } from 'react-native';
import App from './js/App';
import App from './src/App';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);
39 changes: 0 additions & 39 deletions js/lib/PersistentStorage.js

This file was deleted.

16 changes: 8 additions & 8 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions src/lib/PersistentStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* This module is an abstraction around a persistent storage system. This file can be modified to use whatever
* persistent storage method is desired.
*/
import AsyncStorage from '@react-native-community/async-storage';

/**
* Get a key from storage
*
* @param {string} key
* @returns {Promise}
*/
function get(key) {
return AsyncStorage.getItem(key)
.then(val => {
const jsonValue = JSON.parse(val);
return jsonValue;
})
.catch(err => {
console.error(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`);
});
};

/**
* Write a key to storage
*
* @param {string} key
* @param {mixed} val
* @returns {Promise}
*/
function set(key, val) {
return AsyncStorage.setItem(key, JSON.stringify(val));
};

/**
* Empty out the storage (like when the user signs out)
*
* @returns {Promise}
*/
function clear() {
return AsyncStorage.clear();
};

export {
get,
set,
clear,
};
1 change: 0 additions & 1 deletion js/lib/Router/index.js → src/lib/Router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import {
withRouter,
} from 'react-router-dom';

export default {Link, Route, Redirect, Router, Switch, withRouter};
export {Link, Route, Redirect, Router, Switch, withRouter};
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import {
withRouter,
} from 'react-router-native';

export default {Link, Route, Redirect, Router, Switch, withRouter};
export {Link, Route, Redirect, Router, Switch, withRouter};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/index.js → web/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AppRegistry} from 'react-native';
import App from '../js/App';
import App from '../src/App';

AppRegistry.registerComponent('App', () => App);

Expand Down
72 changes: 36 additions & 36 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
mode: 'development',
entry: {
app: './src/index.js',
},
output: {
filename: '[name]-[hash].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
// With the dev server, we need to put this file in the dist folder
filename: 'index.html',
}),
],
module: {
rules: [
// Transpiles ES6 and JSX
{
test: /\.js$/,
exclude: /node_modules|\.native.js$/,
use: {
loader: 'babel-loader',
},
},
mode: 'development',
entry: {
app: './web/index.js',
},
output: {
filename: '[name]-[hash].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'web/index.html',
// With the dev server, we need to put this file in the dist folder
filename: 'index.html',
}),
],
},
resolve: {
alias: {
'react-native$': 'react-native-web',
module: {
rules: [
// Transpiles ES6 and JSX
{
test: /\.js$/,
exclude: /node_modules|\.native.js$/,
use: {
loader: 'babel-loader',
},
},
],
},
resolve: {
alias: {
'react-native$': 'react-native-web',
},
},
},
};