Skip to content

Commit 602bd57

Browse files
author
Pranesh Ravi
committed
initial commit
1 parent 975212e commit 602bd57

26 files changed

+640
-0
lines changed

.babelrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": ["latest", "react", "stage-0"],
3+
"plugins":[
4+
"react-hot-loader/babel",
5+
"transform-decorators-legacy",
6+
]
7+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

app/APIs/apis.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { actions } from '../actions/'
2+
import axios from 'axios'
3+
4+
const noop = () => {}
5+
6+
export const sampleApi = (callback = noop) => dispatch =>
7+
axios('http://google.com')
8+
.then((res) => {
9+
console.log(res)
10+
})
11+
.catch((err) => {
12+
console.log(err)
13+
})

app/APIs/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as APIs from './apis'
2+
3+
export {
4+
APIs,
5+
}

app/actions/_action-types.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const actionTypes = [
2+
'SAMPLE',
3+
]
4+
5+
export default actionTypes.reduce((obj, str)=> {
6+
obj[str] = str
7+
return obj
8+
}, {})

app/actions/actions.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import actionTypes from './_action-types'
2+
import { createAction } from 'redux-actions'
3+
4+
const sample = createAction(actionTypes.SAMPLE)
5+
6+
export default {
7+
sample,
8+
}

app/actions/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import actions from './actions'
2+
3+
export {
4+
actions,
5+
}

app/components/component.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { Component, PropTypes } from 'react'
2+
3+
import style from './style'
4+
5+
export default class Sample extends Component {
6+
constructor(props) {
7+
super(props)
8+
}
9+
10+
render() {
11+
return (
12+
<div className={style.hello}>
13+
<p>wewe.....</p>
14+
</div>
15+
);
16+
}
17+
}

app/components/style.scss

Whitespace-only changes.

app/constants/_style-variables.scss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$color: #000;

app/index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { Component, PropTypes } from 'react'
2+
3+
import { AppContainer } from 'react-hot-loader'
4+
import Layout from './layout/'
5+
import { Provider } from 'react-redux'
6+
import ReactDOM from 'react-dom'
7+
import Test from './components/component'
8+
import easyBind from 'react-easy-bind'
9+
import page from 'page'
10+
import store from './store'
11+
12+
const DefaultStore = store()
13+
14+
function renderIntoDOM(Node, props) {
15+
ReactDOM.render(
16+
<AppContainer>
17+
<Provider store={DefaultStore}>
18+
<Node/>
19+
</Provider>
20+
</AppContainer>,
21+
document.getElementById('app')
22+
)
23+
}
24+
25+
function renderPage(data) {
26+
if (module.hot)
27+
module.hot.accept('./layout/index.jsx', () => {
28+
const NextApp = require('./layout').default
29+
renderIntoDOM(NextApp, data)
30+
})
31+
renderIntoDOM(Layout, data)
32+
}
33+
34+
page('/test', (context) => {
35+
renderPage({ context })
36+
})
37+
38+
page()

app/layout/index.jsx

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from 'react'
2+
3+
import A from '../components/component'
4+
import { APIs } from '../APIs/'
5+
import _ from 'lodash'
6+
import { actions } from '../actions'
7+
import { bindActionCreators } from 'redux'
8+
import { connect } from 'react-redux'
9+
10+
function mapStateToProps(states) {
11+
return { ui: states.reducer };
12+
}
13+
function mapDispatchToProps(dispatch) {
14+
return {
15+
actions: bindActionCreators(
16+
Object.assign(
17+
{},
18+
actions,
19+
APIs,
20+
), dispatch), //Add additional actions inthe Object.assign() method
21+
}
22+
}
23+
24+
class Root extends Component {
25+
constructor(props) {
26+
super(props)
27+
}
28+
29+
render() {
30+
const Component = this.props.component
31+
return (
32+
<A/>
33+
)
34+
}
35+
}
36+
37+
export default connect(
38+
mapStateToProps,
39+
mapDispatchToProps
40+
)(Root)

app/reducers/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from 'redux';
2+
import reducer from './reducer'
3+
4+
export default combineReducers({
5+
reducer,
6+
})

app/reducers/reducer.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import actionTypes from '../actions/_action-types'
2+
import { createState } from './utils'
3+
import { handleActions } from 'redux-actions'
4+
5+
const initialState = {
6+
sample: 'rtsjdhfvjshdv',
7+
}
8+
9+
const reducer = handleActions({
10+
[actionTypes.SAMPLE]: (state, { payload }) =>
11+
createState(state, payload, 'sample'),
12+
}, initialState)
13+
14+
export default reducer

app/reducers/utils/createState.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default (state, payload, key) => {
2+
const newState = {}
3+
newState[key] = payload
4+
return { ...state, ...newState }
5+
}

app/reducers/utils/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import createState from './createState'
2+
3+
export {
4+
createState,
5+
}

app/render.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// import React, { Component, PropTypes } from 'react'
2+
//
3+
// import { AppContainer } from 'react-hot-loader'
4+
// import Layout from './layout/'
5+
// import { Provider } from 'react-redux'
6+
// import ReactDOM from 'react-dom'
7+
// import easyBind from 'react-easy-bind'
8+
// import page from 'page'
9+
// import store from './store'
10+
//
11+
// const DefaultStore = store()
12+
//
13+
// @easyBind
14+
// export default class Render {
15+
// constructor(renderNode) {
16+
// this.renderNode = renderNode
17+
// }
18+
//
19+
// renderIntoDOM(Node, props) {
20+
// ReactDOM.render(
21+
// <Provider store={DefaultStore}>
22+
// <AppContainer>
23+
// <Node {...props}/>
24+
// </AppContainer>
25+
// </Provider>,
26+
// this.renderNode
27+
// )
28+
// }
29+
//
30+
// renderPage(data) {
31+
// if (module.hot)
32+
// module.hot.accept('./layout/index.jsx', () => {
33+
// const NextApp = require('./layout').default
34+
// ReactDOM.unmountComponentAtNode(this.renderNode)
35+
// this.renderIntoDOM(NextApp, data)
36+
// })
37+
// this.renderIntoDOM(Layout, data)
38+
// }
39+
// }

app/store/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { applyMiddleware, compose, createStore } from 'redux'
2+
3+
import reducers from '../reducers/'
4+
import thunk from 'redux-thunk'
5+
6+
export default function configureStore() {
7+
const store = createStore(reducers, compose(
8+
applyMiddleware(thunk),
9+
))
10+
if (module.hot) {
11+
module.hot.accept('../reducers/', () => {
12+
const nextRootReducer = require('../reducers').default
13+
store.replaceReducer(nextRootReducer)
14+
})
15+
}
16+
17+
return store;
18+
}

app/views/index.ejs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>ML Tool</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
</body>
12+
</html>

config/default.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import server from './server/default'
2+
import webpack from './webpack/default'
3+
4+
export {
5+
webpack,
6+
server,
7+
}

config/server/default.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const config = {
2+
host: 'localhost',
3+
port: 3000,
4+
}
5+
6+
export default config

config/webpack/default.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import HTMLwebpackPlugin from 'html-webpack-plugin'
2+
import autoprefixer from 'autoprefixer'
3+
import path from 'path'
4+
import webpack from 'webpack'
5+
const entries = [
6+
'react-hot-loader/patch',
7+
'webpack-hot-middleware/client',
8+
'./app/',
9+
]
10+
11+
12+
export default {
13+
browser: {
14+
entry: entries,
15+
resolve: {
16+
extensions: ['.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.html', '.ejs'],
17+
},
18+
node: {
19+
fs: 'empty',
20+
},
21+
module: {
22+
rules: [
23+
{
24+
test: /\.scss$/,
25+
loaders: [
26+
'style-loader',
27+
'css-loader?modules&importLoaders=1&localIdentName=[path][name]__[local]__[hash:base64:10]',
28+
'sass-loader',
29+
'sass-resources-loader',
30+
'import-glob-loader',
31+
'postcss-loader',
32+
],
33+
},
34+
{
35+
test: /\.jpe?g$|\.gif$|\.png$|\.ico$|\.svg$/,
36+
loader: 'file-loader?name=../img/[name].[ext]',
37+
},
38+
{
39+
test: /\.(woff|woff2|eot|ttf)$/,
40+
loader: 'url-loader',
41+
},
42+
{
43+
test: /\.jsx?$/,
44+
loader: 'babel-loader',
45+
exclude: /node_modules/,
46+
}
47+
],
48+
},
49+
output: {
50+
path: path.resolve('./build/assets/'),
51+
filename: 'bundle.js',
52+
publicPath: '/assets/',
53+
},
54+
plugins: [
55+
new HTMLwebpackPlugin({
56+
filename: '../index.html',
57+
template: './app/views/index.ejs',
58+
}),
59+
new webpack.HotModuleReplacementPlugin(),
60+
new webpack.NoErrorsPlugin(),
61+
new webpack.LoaderOptionsPlugin({
62+
options: {
63+
postcss: [
64+
autoprefixer(),
65+
],
66+
sassResources: [
67+
'./app/constants/_style-variables.scss',
68+
],
69+
context: path.resolve(__dirname, '../../')
70+
}
71+
})
72+
],
73+
},
74+
server: {
75+
entry: './server/',
76+
resolve: {
77+
extensions: ['.js'],
78+
},
79+
node: {
80+
__dirname: false,
81+
__filename: false,
82+
},
83+
externals: /^[a-z\-0-9]+$/,
84+
module: {
85+
rules: [
86+
{
87+
test: /\.js$/,
88+
loader: 'babel-loader',
89+
exclude: /node_modules/,
90+
},
91+
],
92+
},
93+
output: {
94+
path: './',
95+
filename: 'server.js',
96+
libraryTarget: 'commonjs2',
97+
},
98+
},
99+
}

0 commit comments

Comments
 (0)