Skip to content

Commit ca849b3

Browse files
committed
initial commit with partial react support
0 parents  commit ca849b3

File tree

15 files changed

+685
-0
lines changed

15 files changed

+685
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react", "es2015", "stage-1"]
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
bundle.js
3+
npm-debug.log

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ReduxSimpleStarter
2+
3+
Interested in learning [Redux](https://www.udemy.com/react-redux/)?
4+
5+
###Getting Started###
6+
7+
There are two methods for getting started with this repo.
8+
9+
####Familiar with Git?#####
10+
Checkout this repo, install depdencies, then start the gulp process with the following:
11+
12+
```
13+
> git clone [email protected]:StephenGrider/ReduxSimpleStarter.git
14+
> cd ReduxSimpleStarter
15+
> npm install
16+
> npm start
17+
```
18+
19+
####Not Familiar with Git?#####
20+
Click [here](https://github.com/StephenGrider/ReactStarter/releases) then download the .zip file. Extract the contents of the zip file, then open your terminal, change to the project directory, and:
21+
22+
```
23+
> npm install
24+
> npm start
25+
```

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="/style/style.css">
5+
<link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css">
6+
</head>
7+
<body>
8+
<div class="container"></div>
9+
</body>
10+
<script src="/bundle.js"></script>
11+
</html>

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "redux-simple-starter",
3+
"version": "1.0.0",
4+
"description": "Simple starter package for Redux with React and Babel support",
5+
"main": "index.js",
6+
"repository": "[email protected]:StephenGrider/ReduxSimpleStarter.git",
7+
"scripts": {
8+
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
9+
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
10+
"test:watch": "npm run test -- --watch"
11+
},
12+
"author": "",
13+
"license": "ISC",
14+
"devDependencies": {
15+
"babel-core": "^6.2.1",
16+
"babel-loader": "^6.2.0",
17+
"babel-preset-es2015": "^6.1.18",
18+
"babel-preset-react": "^6.1.18",
19+
"chai": "^3.5.0",
20+
"chai-jquery": "^2.0.0",
21+
"jquery": "^2.2.1",
22+
"jsdom": "^8.1.0",
23+
"mocha": "^2.4.5",
24+
"react-addons-test-utils": "^0.14.7",
25+
"webpack": "^1.12.9",
26+
"webpack-dev-server": "^1.14.0"
27+
},
28+
"dependencies": {
29+
"babel-preset-stage-1": "^6.1.18",
30+
"babel-standalone": "^6.7.7",
31+
"esprima": "^2.7.2",
32+
"lodash": "^3.10.1",
33+
"react": "^0.14.3",
34+
"react-addons-create-fragment": "^15.1.0",
35+
"react-codemirror": "^0.2.6",
36+
"react-dom": "^0.14.3",
37+
"react-redux": "^4.0.0",
38+
"react-router": "^2.0.1",
39+
"redux": "^3.0.4"
40+
}
41+
}

src/actions/index.js

Whitespace-only changes.

src/components/app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component } from 'react';
2+
import Editor from './editor';
3+
import Viewer from './viewer';
4+
5+
export default class App extends Component {
6+
constructor(props) {
7+
super(props);
8+
9+
this.state = { code: '' };
10+
}
11+
12+
onEditorChange(code) {
13+
this.setState({ code });
14+
}
15+
16+
render() {
17+
return (
18+
<div>
19+
<Editor onChange={this.onEditorChange.bind(this)} />
20+
<Viewer code={this.state.code} />
21+
</div>
22+
);
23+
}
24+
}

src/components/editor.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component } from 'react';
2+
import CodeMirror from 'react-codemirror';
3+
import 'codemirror/mode/javascript/javascript';
4+
5+
class Editor extends Component {
6+
onChange(code) {
7+
this.props.onChange(code);
8+
}
9+
10+
render() {
11+
return (
12+
<div>
13+
<CodeMirror
14+
value={this.props.code}
15+
onChange={this.onChange.bind(this)}
16+
options={{ mode: 'javascript' }} />
17+
</div>
18+
);
19+
}
20+
}
21+
22+
export default Editor;

src/components/viewer.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import _ from 'lodash';
2+
import React, { Component } from 'react';
3+
import { transform } from 'babel-standalone';
4+
import CreateFragment from 'react-addons-create-fragment';
5+
6+
window.React = React;
7+
window.Component = React.Component;
8+
9+
class Viewer extends Component {
10+
componentWillReceiveProps() {
11+
this.forceUpdate();
12+
}
13+
14+
execute(code) {
15+
let wrappedCode = `(function() {
16+
return (${code});
17+
})()`;
18+
const transformed = transform(code, { presets: ['react', 'es2015'] }).code;
19+
return eval(transformed.replace("'use strict';", ''));
20+
}
21+
22+
renderResult(Result) {
23+
if (Result.prototype && Result.prototype.render) {
24+
return <div><Result /></div>
25+
} else {
26+
return <div>{Result}</div>
27+
}
28+
}
29+
30+
results(code) {
31+
const fragments = _.without(code.split('\n'), '');
32+
33+
try {
34+
this.execute(code);
35+
const results = _.map(fragments, (fragment, index) => {
36+
try {
37+
const group = _.take(fragments, index + 1).join('');
38+
return this.execute(group);
39+
} catch (e) {
40+
41+
}
42+
});
43+
44+
return _.chain(results)
45+
.compact()
46+
.without('use strict')
47+
.map(this.renderResult.bind(this))
48+
.value();
49+
} catch (e) {
50+
return e.toString();
51+
}
52+
}
53+
54+
render() {
55+
return (
56+
<div>
57+
{_.memoize(() => this.results(this.props.code))()}
58+
</div>
59+
);
60+
}
61+
}
62+
63+
export default Viewer;

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { Provider } from 'react-redux';
4+
import { createStore, applyMiddleware } from 'redux';
5+
6+
import App from './components/app';
7+
import reducers from './reducers';
8+
9+
const createStoreWithMiddleware = applyMiddleware()(createStore);
10+
11+
ReactDOM.render(
12+
<Provider store={createStoreWithMiddleware(reducers)}>
13+
<App />
14+
</Provider>
15+
, document.querySelector('.container'));

0 commit comments

Comments
 (0)