Skip to content

Commit 3fc1b73

Browse files
initial commit. [wip] dummy app with routing
1 parent 30d116d commit 3fc1b73

23 files changed

+507
-435
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ end_of_line = crlf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
indent_style = tab
11-
tab_width = 4
10+
indent_style = space
11+
indent_size = 2

.eslintrc

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"browser": true,
5+
"node": true
6+
},
7+
"settings": {
8+
"ecmascript": 7,
9+
"jsx": true
10+
},
11+
"plugins": [
12+
"react"
13+
],
14+
"rules": {
15+
"strict": 0,
16+
"quotes": 1,
17+
"no-unused-vars": 1,
18+
"camelcase": 0,
19+
"no-underscore-dangle": 0,
20+
"no-multi-spaces": 0,
21+
"key-spacing": 0
22+
}
23+
}
24+

babel.server.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("babel/register")({
2-
stage: 0,
3-
plugins: ["typecheck"]
2+
stage: 0,
3+
plugins: ["typecheck"]
44
});
55

66
/**
@@ -10,9 +10,9 @@ global.__CLIENT__ = false;
1010
global.__SERVER__ = true;
1111

1212
if (process.env.NODE_ENV !== "production") {
13-
if (!require("piping")({hook: true, includeModules: true})) {
14-
return;
15-
}
13+
if (!require("piping")({hook: true, includeModules: true})) {
14+
return;
15+
}
1616
}
1717

1818
require("./src/server");

package.json

+24-3
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,46 @@
2929
"dependencies": {
3030
"babel": "5.8.23",
3131
"babel-plugin-typecheck": "1.2.0",
32+
"bootstrap-sass": "^3.3.5",
3233
"h2o2": "4.0.1",
3334
"hapi": "9.3.1",
3435
"history": "1.9.1",
36+
"immutable": "^3.7.5",
3537
"inert": "3.0.1",
3638
"isomorphic-fetch": "2.1.1",
39+
"j-toker": "0.0.10-beta1",
40+
"node-sass": "^3.3.3",
3741
"piping": "0.2.0",
38-
"react": "0.14.0-rc1",
39-
"react-dom": "0.14.0-rc1",
42+
"query-string": "^2.4.2",
43+
"react": "^0.14.0",
44+
"react-bootstrap": "^0.27.1",
45+
"react-dom": "^0.14.0",
4046
"react-inline-css": "2.0.0",
47+
"react-redux": "^3.1.0",
4148
"react-router": "1.0.0-rc1",
42-
"react-transmit": "3.0.6"
49+
"react-router-bootstrap": "^0.19.0",
50+
"react-transmit": "3.0.6",
51+
"redux": "^3.0.2",
52+
"redux-immutable": "^1.3.7",
53+
"redux-immutablejs": "0.0.6",
54+
"redux-router": "^1.0.0-beta3",
55+
"redux-thunk": "^1.0.0",
56+
"serialize-javascript": "^1.1.2",
57+
"thunk": "0.0.1",
58+
"whatwg-fetch": "^0.9.0"
4359
},
4460
"devDependencies": {
4561
"babel-core": "5.8.25",
4662
"babel-loader": "5.3.2",
4763
"babel-runtime": "5.8.24",
4864
"concurrently": "0.1.1",
65+
"css-loader": "^0.19.0",
66+
"extract-text-webpack-plugin": "^0.8.2",
67+
"file-loader": "^0.8.4",
4968
"json-loader": "0.5.3",
5069
"react-hot-loader": "1.3.0",
70+
"sass-loader": "^3.0.0",
71+
"style-loader": "^0.12.4",
5172
"webpack": "1.12.2",
5273
"webpack-dev-server": "1.11.0"
5374
},

src/auth/actions/authenticate.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Auth from "j-toker";
2+
3+
export const AUTHENTICATE_START = "AUTHENTICATE_START";
4+
export const AUTHENTICATE_COMPLETE = "AUTHENTICATE_COMPLETE";
5+
export const AUTHENTICATE_ERROR = "AUTHENTICATE_ERROR";
6+
7+
export function authenticateStart() {
8+
return { type: AUTHENTICATE_START };
9+
}
10+
export function authenticateComplete(user) {
11+
return { type: AUTHENTICATE_COMPLETE, user };
12+
}
13+
export function authenticateError(errors) {
14+
return { type: AUTHENTICATE_ERROR, errors };
15+
}
16+
export function authenticate(config) {
17+
return dispatch => {
18+
dispatch(authenticateStart());
19+
20+
var jqPromise = Auth.configure(config);
21+
22+
jqPromise.then(
23+
(user) => dispatch(authenticateComplete(user)),
24+
({reason}) => dispatch(authenticateError([reason]))
25+
);
26+
27+
return Promise.resolve(jqPromise);
28+
};
29+
}

src/auth/actions/registration.js

Whitespace-only changes.

src/auth/actions/sign-in.js

Whitespace-only changes.

src/auth/actions/sign-out.js

Whitespace-only changes.

src/auth/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import authentication from "./reducers/authenticate";
2+
import user from "./reducers/user";
3+
import authenticate from "./actions/authenticate";
4+
import { combineReducers } from "redux";
5+
6+
const authStateReducer = combineReducers({
7+
authentication,
8+
user
9+
});
10+
11+
export {
12+
authenticate,
13+
authStateReducer
14+
};

src/auth/reducers/authenticate.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Immutable from "immutable";
2+
import { createReducer } from "redux-immutablejs";
3+
import * as A from "../actions/authenticate";
4+
5+
const initialState = Immutable.fromJS({
6+
loading: false,
7+
valid: false,
8+
errors: null
9+
});
10+
11+
export default createReducer(initialState, {
12+
[A.AUTHENTICATE_START]: state => state.set("loading", true),
13+
14+
[A.AUTHENTICATE_COMPLETE]: (state) => {
15+
return state.merge({
16+
loading: false,
17+
errors: null,
18+
valid: true
19+
});
20+
},
21+
22+
[A.AUTHENTICATE_ERROR]: state => state.merge({
23+
loading: false,
24+
errors: "Invalid token",
25+
valid: false
26+
})
27+
});

src/auth/reducers/registration.js

Whitespace-only changes.

src/auth/reducers/sign-in.js

Whitespace-only changes.

src/auth/reducers/sign-out.js

Whitespace-only changes.

src/auth/reducers/user.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Immutable from "immutable";
2+
import { createReducer } from "redux-immutablejs";
3+
import * as AuthActions from "../actions/authenticate";
4+
5+
const initialState = Immutable.fromJS({
6+
attributes: null,
7+
isSignedIn: false,
8+
firstTimeLogin: false,
9+
mustResetPassword: false
10+
});
11+
12+
export default createReducer(initialState, {
13+
[AuthActions.AUTHENTICATE_COMPLETE]: (state, { user }) => state.merge({
14+
attributes: user,
15+
isSignedIn: true
16+
})
17+
});

src/client.js

+45-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
3-
import {Router} from "react-router";
4-
import Transmit from "react-transmit";
5-
import routes from "views/routes";
6-
import {createHistory} from "history";
7-
8-
/**
9-
* Fire-up React Router.
10-
*/
11-
const reactRoot = window.document.getElementById("react-root");
12-
Transmit.render(Router, {routes, history: createHistory()}, reactRoot);
13-
14-
/**
15-
* Detect whether the server-side render has been discarded due to an invalid checksum.
16-
*/
17-
if (process.env.NODE_ENV !== "production") {
18-
if (!reactRoot.firstChild || !reactRoot.firstChild.attributes ||
19-
!reactRoot.firstChild.attributes["data-react-checksum"]) {
20-
console.error("Server-side React render was discarded. Make sure that your initial render does not contain any client-side code.");
21-
}
22-
}
23-
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import {createHistory} from "history";
4+
import {createStore, compose, applyMiddleware} from "redux";
5+
import {reduxReactRouter, ReduxRouter} from "redux-router";
6+
import { routes, reducer } from "./views/routes";
7+
import { Provider } from "react-redux";
8+
import thunk from "redux-thunk";
9+
10+
var store = compose(
11+
applyMiddleware(thunk),
12+
reduxReactRouter({
13+
createHistory,
14+
getRoutes: (args) => {
15+
// dispatch + getState are needed for the route resolvers / redirects. this
16+
// is the only place to get a reference to them before the app is initialized.
17+
//dispatch = args.dispatch;
18+
//getState = args.getState;
19+
return routes;
20+
}
21+
})
22+
)(createStore)(reducer);
23+
24+
25+
/**
26+
* Fire-up React Router.
27+
*/
28+
const reactRoot = window.document.getElementById("react-root");
29+
ReactDOM.render(
30+
<Provider store={store} key="provider">
31+
<ReduxRouter children={routes} />
32+
</Provider>
33+
, reactRoot);
34+
35+
36+
/**
37+
* Detect whether the server-side render has been discarded due to an invalid checksum.
38+
*/
39+
if (process.env.NODE_ENV !== "production") {
40+
if (!reactRoot.firstChild || !reactRoot.firstChild.attributes ||
41+
!reactRoot.firstChild.attributes["data-react-checksum"]) {
42+
console.error("Server-side React render was discarded. Make sure that your initial render does not contain any client-side code.");
43+
}
44+
}
45+

0 commit comments

Comments
 (0)