File tree 27 files changed +9244
-38
lines changed
27 files changed +9244
-38
lines changed Original file line number Diff line number Diff line change
1
+ # Misc
2
+ .DS_Store
3
+ .vscode /
4
+
5
+ # Java
6
+ .classpath
7
+ .project
8
+ .settings /
9
+ bin /
10
+ target /
11
+ tomcat.8080 /
12
+
13
+ # Client
14
+ node_modules
Original file line number Diff line number Diff line change 9
9
<url >http://maven.apache.org</url >
10
10
<properties >
11
11
<tomcat .version>8.5.2</tomcat .version>
12
+ <maven .compiler.source>1.6</maven .compiler.source>
13
+ <maven .compiler.target>1.6</maven .compiler.target>
12
14
</properties >
13
15
<dependencies >
14
16
<dependency >
Original file line number Diff line number Diff line change 8
8
import org .apache .catalina .webresources .DirResourceSet ;
9
9
import org .apache .catalina .webresources .StandardRoot ;
10
10
11
+ // import java.io.FileReader;
12
+
13
+ // import javax.script.ScriptEngine;
14
+ // import javax.script.ScriptEngineManager;
15
+ // import javax.script.ScriptException;
16
+
11
17
public class Main {
12
18
13
19
public static void main (String [] args ) throws Exception {
@@ -37,5 +43,12 @@ public static void main(String[] args) throws Exception {
37
43
38
44
tomcat .start ();
39
45
tomcat .getServer ().await ();
46
+
47
+
48
+ // Server-rendering with Nashorn
49
+ // ScriptEngine nashorn = new ScriptEngineManager().getEngineByName("nashorn");
50
+ // nashorn.eval(new FileReader(webappDirLocation + "public/bundle.js"));
51
+ // String markup = nashorn.invokeFunction("renderOnServer");
52
+ // Then Pass markup as Java variable
40
53
}
41
54
}
Original file line number Diff line number Diff line change 25
25
"indent" : [" error" , 2 ],
26
26
"linebreak-style" : [" error" , " unix" ],
27
27
"quotes" : [" error" , " double" ],
28
+ // Append "G_" to all global variables
29
+ // "no-unused-vars": ["error", { "varsIgnorePattern": "G_" }],
28
30
// Get rid of React warnings
29
31
"react/jsx-uses-react" : [2 ],
30
32
"react/jsx-uses-vars" : [2 ],
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
-
2
+ import { customAddEventListener } from "../helpers/util" ;
3
+ import { importModules } from "../helpers/moduleLoader" ;
3
4
import Aux from "./Aux" ;
4
5
import Header from "./header" ;
5
6
import Routes from "./Routes" ;
@@ -12,12 +13,25 @@ import "../scss/style.scss";
12
13
// To avoid array notation and manually added keys to each of the element,
13
14
// you can use an Aux helper function that simply returns all its children.
14
15
// const Aux = props => props.children;
15
- export default ( ) => (
16
- < Aux >
17
- < Header />
18
- < Routes />
19
- </ Aux >
20
- ) ;
16
+ export default class App extends React . Component {
17
+ componentDidMount ( ) {
18
+ // lazy load routes
19
+ customAddEventListener ( window , "load" , this . lazyLoadRoutes ) ;
20
+ }
21
+
22
+ lazyLoadRoutes = ( ) => {
23
+ this . props . history && importModules ( this . props . history ) ;
24
+ } ;
25
+
26
+ render ( ) {
27
+ return (
28
+ < Aux >
29
+ < Header />
30
+ < Routes />
31
+ </ Aux >
32
+ ) ;
33
+ }
34
+ }
21
35
22
36
// Render modal outside DOM tree
23
37
// render() {
Original file line number Diff line number Diff line change
1
+ // Reference: https://scotch.io/tutorials/lazy-loading-routes-in-react
2
+
3
+ import React from "react" ;
4
+
5
+ export default function asyncComponent ( getComponent ) {
6
+ class AsyncComponent extends React . Component {
7
+ static Component = null ;
8
+ state = { Component : AsyncComponent . Component } ;
9
+
10
+ componentWillMount ( ) {
11
+ if ( ! this . state . Component ) {
12
+ getComponent ( ) . then ( Component => {
13
+ AsyncComponent . Component = Component ;
14
+ this . setState ( { Component } ) ;
15
+ } ) ;
16
+ }
17
+ }
18
+ render ( ) {
19
+ const { Component } = this . state ;
20
+ if ( Component ) {
21
+ return < Component { ...this . props } /> ;
22
+ }
23
+ return null ;
24
+ }
25
+ }
26
+ return AsyncComponent ;
27
+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import App from "./App";
7
7
export default ( ) => (
8
8
< Provider store = { store } >
9
9
< ConnectedRouter history = { history } >
10
- < App />
10
+ < App history = { history } />
11
11
</ ConnectedRouter >
12
12
</ Provider >
13
13
) ;
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import { Switch , Route } from "react-router-dom" ;
3
- import Home from "./home" ;
4
- import About from "./about" ;
3
+ import { chunkLoadFailed } from "../helpers/moduleLoader" ;
4
+ // import Home from "./home";
5
+ // import About from "./about";
6
+ import asyncComponent from "./AsyncComponent" ;
7
+
8
+ const Home = asyncComponent ( ( ) =>
9
+ import ( /* webpackChunkName: "homepage" */ "./home" )
10
+ . then ( module => module . default )
11
+ . catch ( chunkLoadFailed )
12
+ ) ;
13
+ const About = asyncComponent ( ( ) =>
14
+ import ( /* webpackChunkName: "aboutpage" */ "./about" )
15
+ . then ( module => module . default )
16
+ . catch ( chunkLoadFailed )
17
+ ) ;
5
18
6
19
export default ( ) => (
7
20
< Switch >
Original file line number Diff line number Diff line change
1
+ export default ( ) => "Brands!!!" ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import MaterialButton from "../material-button";
3
3
4
4
export default props => (
5
5
< section className = "g-flex-item-stretch" >
6
- < p className = "counter" > ❤️ Rate : { props . count } %</ p >
6
+ < p className = "counter" > ❤️ Rates : { props . count } %</ p >
7
7
8
8
< MaterialButton
9
9
text = "Increment"
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import Aux from "../Aux" ;
3
+ import { welcome } from "../../labels" ;
3
4
4
5
export default ( ) => (
5
6
< Aux >
@@ -10,5 +11,6 @@ export default () => (
10
11
< p className = "home__note" >
11
12
Also now supports custom HTML attributes eg: ❤️ 🦄
12
13
</ p >
14
+ { welcome }
13
15
</ Aux >
14
16
) ;
Original file line number Diff line number Diff line change @@ -48,3 +48,10 @@ const mapDispatchToProps = dispatch =>
48
48
// })
49
49
50
50
export default connect ( mapStateToProps , mapDispatchToProps ) ( Home ) ;
51
+
52
+ /* To push to history:
53
+ import { push } from "react-router-redux";
54
+ push("/about")
55
+ -- OR --
56
+ this.props.histtory.push("/about")
57
+ */
Original file line number Diff line number Diff line change
1
+ export default ( ) => "Search!!!" ;
Original file line number Diff line number Diff line change
1
+ export function getLanguage ( ) {
2
+ return window . __INITIAL_STATE__ . language ;
3
+ }
Original file line number Diff line number Diff line change
1
+ import { contains } from "./util" ;
2
+
3
+ const importModulesOnDemand = ( location , action ) => {
4
+ if ( action === "PUSH" ) {
5
+ if ( contains ( location . pathname , "about" ) ) {
6
+ import ( /* webpackChunkName: "brandspage" */ "../components/brands" )
7
+ . then ( module => module )
8
+ . catch ( chunkLoadFailed ) ;
9
+ }
10
+ }
11
+ } ;
12
+
13
+ export function chunkLoadFailed ( err ) {
14
+ console . error ( "Failed to load chunk => " + err ) ;
15
+ }
16
+
17
+ export function importModules ( history ) {
18
+ // Load immediate dependencies => modules required in all pages
19
+ import ( /* webpackChunkName: "searchpage" */ "../components/search" )
20
+ . then ( module => module )
21
+ . catch ( chunkLoadFailed ) ;
22
+
23
+ // Load current page immediate dependencies => load accessible modules from the page
24
+ history . listen ( importModulesOnDemand ) ;
25
+ }
Original file line number Diff line number Diff line change @@ -85,5 +85,32 @@ export function getUniqueId() {
85
85
"uid-" + new Date ( ) . getTime ( ) + parseInt ( Math . random ( ) * 100 ) . toString ( )
86
86
) ;
87
87
}
88
+ export function contains ( search , target ) {
89
+ return ! ! ~ search . indexOf ( target ) ;
90
+ }
88
91
// END: String creation/manipulation
89
92
//<<<<<<<<<<<<<<<<<<<<<<<<
93
+
94
+ //>>>>>>>>>>>>>>>>>>>>>>>>
95
+ // START: Handlers
96
+ export function customAddEventListener (
97
+ elem ,
98
+ event ,
99
+ callback ,
100
+ useCapture = false
101
+ ) {
102
+ if ( elem . addEventListener ) {
103
+ elem . addEventListener ( event , callback , useCapture ) ;
104
+ } else {
105
+ elem . attachEvent ( `on${ event } ` , callback ) ;
106
+ }
107
+ }
108
+ export function customRemoveEventListener ( elem , event , callback ) {
109
+ if ( elem . removeEventListener ) {
110
+ elem . removeEventListener ( event , callback ) ;
111
+ } else {
112
+ elem . detachEvent ( `on${ event } ` , callback ) ;
113
+ }
114
+ }
115
+ // END: Handlers
116
+ //<<<<<<<<<<<<<<<<<<<<<<<<
Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ const rootEl = document.querySelector("#root");
6
6
7
7
render ( < Provider /> , rootEl ) ;
8
8
9
+ // window.renderOnClient = function () {
10
+ // render(<Provider />, rootEl);
11
+ // };
12
+
13
+ // window.renderOnServer = function () {
14
+ // return React.renderToString(<Provider />);
15
+ // };
16
+
9
17
if ( module . hot ) {
10
18
module . hot . accept ( "./components/Provider" , ( ) => {
11
19
const NextProvider = require ( "./components/Provider" ) . default ;
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ welcome : "Arabic text"
3
+ } ;
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ welcome : "Welcome!!!"
3
+ } ;
Original file line number Diff line number Diff line change
1
+ import { getLanguage } from "../helpers/globals" ;
2
+ module . exports = require ( "./" + getLanguage ( ) ) ;
Original file line number Diff line number Diff line change 1
1
import { combineReducers } from "redux" ;
2
2
import { routerReducer } from "react-router-redux" ;
3
3
import counter from "./counter" ;
4
+ import language from "./language" ;
4
5
5
6
export default combineReducers ( {
6
7
routing : routerReducer ,
7
- counter
8
+ counter,
9
+ language
8
10
} ) ;
Original file line number Diff line number Diff line change
1
+ export default ( state = { } ) => {
2
+ return state ;
3
+ } ;
You can’t perform that action at this time.
0 commit comments