commit 9457b36f462c105b3856af0c1f4cb98b9e380db9
parent 6433dbe8b65451a329c98b520fa2ba2d28c64d87
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Thu, 27 Aug 2015 00:51:42 +0300
Use UpperCamelCase for singletones
...according to the AirBnb JavaScript Style Guide
Diffstat:
10 files changed, 108 insertions(+), 108 deletions(-)
diff --git a/src/Router.js b/src/Router.js
@@ -0,0 +1,38 @@
+/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
+
+import React from 'react';
+import Router from 'react-routing/src/Router';
+import http from './core/HttpClient';
+import App from './components/App';
+import ContentPage from './components/ContentPage';
+import ContactPage from './components/ContactPage';
+import LoginPage from './components/LoginPage';
+import RegisterPage from './components/RegisterPage';
+import NotFoundPage from './components/NotFoundPage';
+import ErrorPage from './components/ErrorPage';
+
+const router = new Router(on => {
+
+ on('*', async (state, next) => {
+ const component = await next();
+ return component && <App context={state.context}>{component}</App>;
+ });
+
+ on('/contact', async () => <ContactPage />);
+
+ on('/login', async () => <LoginPage />);
+
+ on('/register', async () => <RegisterPage />);
+
+ on('*', async (state) => {
+ const content = await http.get(`/api/content?path=${state.path}`);
+ return content && <ContentPage {...content} />;
+ });
+
+ on('error', (state, error) => state.statusCode === 404 ?
+ <App context={state.context} error={error}><NotFoundPage /></App> :
+ <App context={state.context} error={error}><ErrorPage /></App>);
+
+});
+
+export default router;
diff --git a/src/app.js b/src/app.js
@@ -3,9 +3,9 @@
import 'babel/polyfill';
import ReactDOM from 'react-dom';
import FastClick from 'fastclick';
-import dispatcher from './core/dispatcher';
-import router from './router';
-import location from './core/location';
+import Dispatcher from './core/Dispatcher';
+import Router from './Router';
+import Location from './core/Location';
import ActionTypes from './constants/ActionTypes';
const container = document.getElementById('app');
@@ -30,16 +30,16 @@ const context = {
function run() {
FastClick.attach(document.body);
- router.dispatch({ path: window.location.pathname, context }, (state, component) => {
+ Router.dispatch({ path: window.location.pathname, context }, (state, component) => {
ReactDOM.render(component, container, () => {
let css = document.getElementById('css');
css.parentNode.removeChild(css);
});
});
- dispatcher.register(action => {
+ Dispatcher.register(action => {
if (action.type === ActionTypes.CHANGE_LOCATION) {
- router.dispatch({ path: action.path, context }, (state, component) => {
+ Router.dispatch({ path: action.path, context }, (state, component) => {
ReactDOM.render(component, container);
});
}
@@ -47,7 +47,7 @@ function run() {
}
function handlePopState(event) {
- location.navigateTo(window.location.pathname, { replace: !!event.state });
+ Location.navigateTo(window.location.pathname, { replace: !!event.state });
}
// Run the application when both DOM is ready
diff --git a/src/core/dispatcher.js b/src/core/Dispatcher.js
diff --git a/src/core/HttpClient.js b/src/core/HttpClient.js
@@ -0,0 +1,33 @@
+/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
+
+import request from 'superagent';
+import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
+
+const getUrl = path => path.startsWith('http') ?
+ path : ExecutionEnvironment.canUseDOM ? path :
+ process.env.WEBSITE_HOSTNAME ?
+ `http://${process.env.WEBSITE_HOSTNAME}${path}` :
+ `http://127.0.0.1:${global.server.get('port')}${path}`;
+
+const HttpClient = {
+
+ get: path => new Promise((resolve, reject) => {
+ request
+ .get(getUrl(path))
+ .accept('application/json')
+ .end((err, res) => {
+ if (err) {
+ if (err.status === 404) {
+ resolve(null);
+ } else {
+ reject(err);
+ }
+ } else {
+ resolve(res.body);
+ }
+ });
+ })
+
+};
+
+export default HttpClient;
diff --git a/src/core/Location.js b/src/core/Location.js
@@ -0,0 +1,26 @@
+/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
+
+import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
+import Dispatcher from '../core/Dispatcher';
+import ActionTypes from '../constants/ActionTypes';
+
+const location = {
+
+ navigateTo(path, options) {
+ if (canUseDOM) {
+ if (options && options.replace) {
+ window.history.replaceState({}, document.title, path);
+ } else {
+ window.history.pushState({}, document.title, path);
+ }
+ }
+
+ Dispatcher.dispatch({
+ type: ActionTypes.CHANGE_LOCATION,
+ path
+ });
+ }
+
+};
+
+export default location;
diff --git a/src/core/http.js b/src/core/http.js
@@ -1,33 +0,0 @@
-/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
-
-import request from 'superagent';
-import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
-
-const getUrl = path => path.startsWith('http') ?
- path : ExecutionEnvironment.canUseDOM ? path :
- process.env.WEBSITE_HOSTNAME ?
- `http://${process.env.WEBSITE_HOSTNAME}${path}` :
- `http://127.0.0.1:${global.server.get('port')}${path}`;
-
-const http = {
-
- get: path => new Promise((resolve, reject) => {
- request
- .get(getUrl(path))
- .accept('application/json')
- .end((err, res) => {
- if (err) {
- if (err.status === 404) {
- resolve(null);
- } else {
- reject(err);
- }
- } else {
- resolve(res.body);
- }
- });
- })
-
-};
-
-export default http;
diff --git a/src/core/location.js b/src/core/location.js
@@ -1,26 +0,0 @@
-/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
-
-import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
-import dispatcher from '../core/dispatcher';
-import ActionTypes from '../constants/ActionTypes';
-
-const location = {
-
- navigateTo(path, options) {
- if (canUseDOM) {
- if (options && options.replace) {
- window.history.replaceState({}, document.title, path);
- } else {
- window.history.pushState({}, document.title, path);
- }
- }
-
- dispatcher.dispatch({
- type: ActionTypes.CHANGE_LOCATION,
- path
- });
- }
-
-};
-
-export default location;
diff --git a/src/router.js b/src/router.js
@@ -1,38 +0,0 @@
-/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
-
-import React from 'react';
-import Router from 'react-routing/src/Router';
-import http from './core/http';
-import App from './components/App';
-import ContentPage from './components/ContentPage';
-import ContactPage from './components/ContactPage';
-import LoginPage from './components/LoginPage';
-import RegisterPage from './components/RegisterPage';
-import NotFoundPage from './components/NotFoundPage';
-import ErrorPage from './components/ErrorPage';
-
-const router = new Router(on => {
-
- on('*', async (state, next) => {
- const component = await next();
- return component && <App context={state.context}>{component}</App>;
- });
-
- on('/contact', async () => <ContactPage />);
-
- on('/login', async () => <LoginPage />);
-
- on('/register', async () => <RegisterPage />);
-
- on('*', async (state) => {
- const content = await http.get(`/api/content?path=${state.path}`);
- return content && <ContentPage {...content} />;
- });
-
- on('error', (state, error) => state.statusCode === 404 ?
- <App context={state.context} error={error}><NotFoundPage /></App> :
- <App context={state.context} error={error}><ErrorPage /></App>);
-
-});
-
-export default router;
diff --git a/src/server.js b/src/server.js
@@ -6,7 +6,7 @@ import fs from 'fs';
import path from 'path';
import express from 'express';
import ReactDOM from 'react-dom/server';
-import router from './router';
+import Router from './Router';
const server = global.server = express();
@@ -38,7 +38,7 @@ server.get('*', async (req, res, next) => {
onPageNotFound: () => statusCode = 404
};
- await router.dispatch({ path: req.path, context }, (state, component) => {
+ await Router.dispatch({ path: req.path, context }, (state, component) => {
data.body = ReactDOM.renderToString(component);
data.css = css.join('');
});
diff --git a/src/utils/Link.js b/src/utils/Link.js
@@ -1,7 +1,7 @@
/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
import invariant from 'fbjs/lib/invariant';
-import location from '../core/location';
+import Location from '../core/Location';
function handleClick(event) {
@@ -23,7 +23,7 @@ function handleClick(event) {
var path = el.pathname + el.search + (el.hash || '');
event.preventDefault();
- location.navigateTo(path);
+ Location.navigateTo(path);
}
export default { handleClick };