Move react example to create-react-app and try to get it syncing

This commit is contained in:
Bryan Goldstein 2017-03-21 04:46:57 +00:00
parent 527489d835
commit 8a95deb4fd
19 changed files with 1772 additions and 148 deletions

View File

@ -1,11 +0,0 @@
{
"presets": [
"react",
"env",
"stage-0"
],
"plugins": [
"transform-decorators-legacy",
"transform-eval"
]
}

View File

@ -1,3 +1,18 @@
data.json
node_modules
npm-debug.log
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/node_modules
# testing
/coverage
# production
/build
# misc
.DS_Store
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
import React, { Component } from 'react'
import { render } from 'react-dom'
import Todos from './todos'
import Chat from './chat'
import Json from './json'
const App = _ =>
<div>
<h1>React Examples</h1>
<h2>Todo</h2>
<Todos />
<br />
<hr />
<h2>Chat</h2>
<Chat />
<br />
<hr />
<h2>Json</h2>
<Json />
</div>
render(<App />, document.getElementById('app'))

View File

@ -1,12 +0,0 @@
<!doctype html>
<html>
<head>
<title>Gun - React Examples</title>
<meta charset="utf-8" />
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@ -1,38 +1,22 @@
{
"name": "gun-react-examples",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node start",
"dev": "nodemon --config .nodemon.json start"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-eval": "^6.8.0",
"babel-preset-env": "^1.2.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"css-loader": "^0.26.1",
"file-loader": "^0.9.0",
"html-webpack-plugin": "^2.26.0",
"json-loader": "^0.5.4",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.14.0"
},
"version": "1.1.0",
"private": true,
"dependencies": {
"babel": "^6.5.2",
"babel-polyfill": "^6.20.0",
"express": "^4.14.1",
"lodash": "^4.17.4",
"gun": "file:../..",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack-dev-middleware": "^1.9.0"
"react-dom": "^15.4.2"
},
"devDependencies": {
"express": "^4.15.2",
"express-http-proxy": "^0.11.0",
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"server": "PORT=8081 node ./server.js"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Gun - React Examples</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>

View File

@ -1,18 +1,26 @@
import express from 'express'
import Gun from '../..'
import webpack from 'webpack'
import WebpackDevMiddleware from 'webpack-dev-middleware'
import config from './webpack.config'
const app = express()
const gun = Gun()
Gun({web: app})
const compiler = webpack(config)
const devMiddleware = WebpackDevMiddleware(compiler)
app.use(devMiddleware)
app.listen(4000)
console.log("If modules not found, run `npm install` in /example folder!"); // git subtree push -P examples heroku master // OR // git subtree split -P examples master && git push heroku [['HASH']]:master --force
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8081;
var host = process.env.OPENSHIFT_NODEJS_HOST || process.env.VCAP_APP_HOST || process.env.HOST || 'localhost';
var express = require('express');
var proxy = require('express-http-proxy');
var http = require('http');
var app = express();
var server = http.createServer(app);
var Gun = require('gun');
var gun = Gun({
file: 'data.json',
web: server,
s3: {
key: '', // AWS Access Key
secret: '', // AWS Secret Token
bucket: '' // The bucket you want to save into
}
});
app.use(Gun.serve);
app.use(proxy(host + ':8080'));
server.listen(port);
console.log('Server started on port ' + port + ' with /gun');

26
examples/react/src/App.js Normal file
View File

@ -0,0 +1,26 @@
import React, { Component } from 'react';
import Todos from './Todos'
import Chat from './Chat'
import Json from './Json'
class App extends Component {
render() {
return (
<div>
<h1>React Examples</h1>
<h2>Todo</h2>
<Todos />
<br />
<hr />
<h2>Chat</h2>
<Chat />
<br />
<hr />
<h2>Json</h2>
<Json />
</div>
);
}
}
export default App;

View File

@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import Gun from '../../gun'
import Gun from 'gun'
const gun = Gun().get('chat')
const gun = Gun(location.origin + '/gun').get('chat')
const formatMsgs = msgs => Object.keys(msgs)
.map(key => ({ key, ...msgs[key] }))
.filter(m => Boolean(m.when) && m.key !== '_')

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import Gun from '../../gun'
import Gun from 'gun'
const gun = Gun().get('json')
const gun = Gun(location.origin + '/gun').get('json')
const formatJson = json =>
Object.keys(json)
.map(key => ({ key, val: json[key]}))

View File

@ -1,8 +1,8 @@
import './style.css'
import React, { Component } from 'react'
import Gun from '../../gun'
import Gun from 'gun'
const gun = Gun().get('todos')
const gun = Gun(location.origin + '/gun').get('todos')
const formatTodos = todos => Object.keys(todos)
.map(key => ({ key, val: todos[key] }))
.filter(t => Boolean(t.val) && t.key !== '_')

View File

@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}

View File

@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
ReactDOM.render(
<App />,
document.getElementById('root')
);

View File

@ -1,3 +0,0 @@
require('source-map-support').install()
require('babel-register')
require('./server')

View File

@ -1,38 +0,0 @@
var webpack = require('webpack')
var path = require('path')
var HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './app.js',
devtool: 'source-map',
output: {
filename: '[name].js?[hash]',
path: path.join(__dirname, 'public'),
},
module: {
loaders: [
{
test: /\.css$/,
loader: 'style!css',
},
{
test: /\.(png|gif|jpg|jpeg|woff)$/,
loader: 'url',
},
{
test: /\.(eot|ttf|svg|ico)$/,
loader: 'file',
},
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './index.html'
})
],
}