-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d93bfd7
commit 934ba4a
Showing
15 changed files
with
24,906 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Minimal example on how to run react with kontraktor (without node/babel) | ||
|
||
Uses a java implemented jsx compiler. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.sonatype.oss</groupId> | ||
<artifactId>oss-parent</artifactId> | ||
<version>7</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.ruedigermoeller</groupId> | ||
<artifactId>react-intrinsic-minimal</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<configuration> | ||
<additionalparam>-Xdoclint:none</additionalparam> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<!-- this is used for inheritance merges --> | ||
<phase>package</phase> | ||
<!-- bind to the packaging phase --> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>de.ruedigermoeller</groupId> | ||
<artifactId>kontraktor-http</artifactId> | ||
<version>4.05</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
68 changes: 68 additions & 0 deletions
68
examples/react-intrinsic-minimal/src/main/java/sample/reactmini/ReactMiniApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package sample.reactmini; | ||
|
||
import org.nustaq.kontraktor.Actor; | ||
import org.nustaq.kontraktor.IPromise; | ||
import org.nustaq.kontraktor.Scheduler; | ||
import org.nustaq.kontraktor.annotations.Local; | ||
import org.nustaq.kontraktor.impl.SimpleScheduler; | ||
import org.nustaq.kontraktor.remoting.encoding.SerializerType; | ||
import org.nustaq.kontraktor.remoting.http.undertow.Http4K; | ||
import org.nustaq.kontraktor.webapp.transpiler.JSXIntrinsicTranspiler; | ||
|
||
import java.io.File; | ||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.IntStream; | ||
|
||
/** | ||
* minimal implementation of session based server (incl. load balancing) | ||
*/ | ||
public class ReactMiniApp extends Actor<ReactMiniApp> { | ||
|
||
private Scheduler clientThreads[]; | ||
private Random rand = new Random(); | ||
|
||
@Local | ||
public void init(int nthreads) { | ||
clientThreads = new Scheduler[nthreads]; | ||
IntStream.range(0,nthreads) | ||
.forEach( i -> clientThreads[i] = new SimpleScheduler(100, true /*Important!*/ )); | ||
} | ||
|
||
public IPromise<ReactMiniSession> login(String username) { | ||
if ( "".equals(username.trim()) ) { | ||
return reject("empty username"); | ||
} | ||
ReactMiniSession session = AsActor( | ||
ReactMiniSession.class, | ||
// randomly distribute session actors among clientThreads | ||
clientThreads[rand.nextInt(clientThreads.length)] | ||
); | ||
session.init(username); | ||
return resolve(session); // == new Promise(session) | ||
} | ||
|
||
public static void main(String[] args) { | ||
boolean DEVMODE = true; | ||
|
||
if ( ! new File("./src/main/web/client/index.html").exists() ) { | ||
System.out.println("Please run with working dir: '[..]/react-intrinsic-minimal"); | ||
System.exit(-1); | ||
} | ||
|
||
ReactMiniApp app = AsActor(ReactMiniApp.class); | ||
app.init(4); | ||
|
||
Http4K.Build("localhost", 8080) | ||
.resourcePath("/") | ||
.elements("./src/main/web/client","./src/main/web/lib") | ||
.transpile("jsx", new JSXIntrinsicTranspiler(DEVMODE,!DEVMODE)) | ||
.allDev(DEVMODE) | ||
.buildResourcePath() | ||
.httpAPI("/api", app) | ||
.serType(SerializerType.JsonNoRef) | ||
.setSessionTimeout(TimeUnit.MINUTES.toMillis(30)) | ||
.buildHttpApi() | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/react-intrinsic-minimal/src/main/java/sample/reactmini/ReactMiniSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sample.reactmini; | ||
|
||
import org.nustaq.kontraktor.Actor; | ||
import org.nustaq.kontraktor.IPromise; | ||
import org.nustaq.kontraktor.Promise; | ||
import org.nustaq.kontraktor.remoting.base.RemotedActor; | ||
import org.nustaq.kontraktor.util.Log; | ||
|
||
public class ReactMiniSession extends Actor<ReactMiniSession> implements RemotedActor { | ||
|
||
private String name; | ||
|
||
public void init(String name) { | ||
this.name = name; | ||
} | ||
|
||
public IPromise<String> greet(String who) { | ||
return new Promise("Hello "+who+" from "+name); | ||
} | ||
|
||
/** | ||
* interface RemotedActor, session time out notification callback | ||
*/ | ||
@Override | ||
public void hasBeenUnpublished() { | ||
Log.Info(this,"bye "+name); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
examples/react-intrinsic-minimal/src/main/web/client/css/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
a { | ||
color: white; | ||
text-decoration: none; /* no underline */ | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; /* no underline */ | ||
} | ||
|
||
input { | ||
display: block; | ||
margin: 0; | ||
width: 100%; | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
appearance: none; | ||
box-shadow: none; | ||
border-radius: none; | ||
padding: 6px; | ||
border: solid 1px #dcdcdc; | ||
transition: box-shadow 0.3s, border 0.3s; | ||
box-sizing: border-box; | ||
} | ||
input:focus { | ||
outline: none; | ||
border: solid 1px #707070; | ||
box-shadow: 0 0 5px 1px #969696; | ||
} | ||
|
||
.defbtn { | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
appearance: none; | ||
box-shadow: none; | ||
border-radius: none; | ||
padding: 6px 8px; | ||
border: solid 1px #dcdcdc; | ||
transition: box-shadow 0.3s, border 0.3s; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
background: #fff; | ||
} | ||
.defbtn:hover { | ||
outline: none; | ||
border: solid 1px #707070; | ||
box-shadow: 0 0 2px 1px #969696; | ||
} | ||
|
||
.lightbtn { | ||
font-family: sans-serif; | ||
font-size: 12px; | ||
appearance: none; | ||
box-shadow: none; | ||
border-radius: none; | ||
padding: 8px 8px; | ||
border: none; | ||
transition: box-shadow 0.3s, border 0.3s; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
/*background: #fff;*/ | ||
} | ||
.lightbtn:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
#root { | ||
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#499bea+0,207ce5+100;Blue+3d+%237 */ | ||
background: #499bea; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #499bea 0%, #207ce5 100%); /* FF3.6-15 */ | ||
background: -webkit-linear-gradient(top, #499bea 0%,#207ce5 100%); /* Chrome10-25,Safari5.1-6 */ | ||
background: linear-gradient(to bottom, #499bea 0%,#207ce5 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ | ||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#499bea', endColorstr='#207ce5',GradientType=0 ); /* IE6-9 */ | ||
color: white; | ||
} | ||
|
||
#root > [data-reactroot] { | ||
flex-flow: column !important; | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/react-intrinsic-minimal/src/main/web/client/greeter.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {Component} from 'react'; | ||
import {Fader} from "./util"; | ||
|
||
class Greeter extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
greeting: '...' | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
global.session.greet('World') | ||
.then( (res,err) => { | ||
console.log("receive greeting ",res,err); | ||
this.setState({greeting: err ? err : res }); | ||
}); | ||
} | ||
|
||
render() { | ||
// enforce component creation to trigger fading | ||
return ( | ||
<Fader> | ||
{ this.state.greeting == '...' ? | ||
<div>{this.state.greeting}</div> | ||
: | ||
<div>{this.state.greeting}</div> | ||
} | ||
</Fader> | ||
); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
examples/react-intrinsic-minimal/src/main/web/client/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
<html lang="" style="height: 100%;"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>react minimal sample</title> | ||
<link rel="stylesheet" type="text/css" href="css/index.css"> | ||
</head> | ||
|
||
<body style="min-height: 100%; display: flex;"> | ||
|
||
<div id="root" style="width: 80%;margin: 0 auto;"></div> | ||
|
||
<!-- | ||
manual import as kontraktor-client has no bundled UMD build currently. | ||
kontraktor classes are available globally and need no 'import' inside jsx | ||
--> | ||
<script src="kontraktor-common.js"></script> | ||
<script src="kontraktor-client.js"></script> | ||
|
||
<script> | ||
// in order to make UMD builds work with 'import' we need a map of library filename to library Object, | ||
// as libs arent loaded yet, provide lambdas. | ||
// its also possible to construct 'virtual' library object in case lib exposes its stuff globally | ||
// like 'libFilenameWithoutExtension': () => { return { fancyFunc: fancyFunc,.. } } | ||
klibmap = { | ||
react: () => React | ||
}; | ||
</script> | ||
|
||
<script src="index.jsx"></script> | ||
|
||
<!-- take care: in dev mode index.jsx is loaded deferred (side effect of document.write --> | ||
|
||
</body> | ||
|
||
</html> |
Oops, something went wrong.