Skip to content

Commit c968794

Browse files
committed
pushing the react examples
1 parent 6511995 commit c968794

15 files changed

+658
-2
lines changed

.classpath

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/classes" path="src/main/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="output" path="target/classes"/>
26+
</classpath>

.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>jsweet-react-examples-2</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
</natures>
23+
</projectDescription>

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,4 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202+

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# jsweet-examples-react
2-
Some examples for using React.js in Java (powered by JSweet)
1+
# Get started with React.js in Java!
2+
3+
Thanks to JSweet, you can now play with React.js in Java.
4+
5+
## Usage
6+
7+
```
8+
> git clone https://github.com/cincheo/jsweet-examples-react.git
9+
> cd jsweet-examples-react
10+
> mvn generate-sources
11+
> firefox webapp/<example-name>.html
12+
```
13+
14+
## Prerequisites
15+
16+
- Java 8 JDK is required. Type in ``java -version`` in a console to make sure that you have a >= 1.8 JDK.
17+
- The `node` and `npm` executables must be in the path (https://nodejs.org).
18+
- Install Maven (https://maven.apache.org/install.html).
19+

pom.xml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.jsweet</groupId>
5+
<artifactId>jsweet-quickstart</artifactId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
<name>JSweet quick start</name>
8+
<description>A simple project structure to get started with JSweet</description>
9+
<developers>
10+
<developer>
11+
<id>rpawlak</id>
12+
<name>Renaud Pawlak</name>
13+
<email>[email protected]</email>
14+
</developer>
15+
</developers>
16+
<licenses>
17+
<license>
18+
<name>The Apache Software License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
<pluginRepositories>
24+
<pluginRepository>
25+
<id>jsweet-plugins-release</id>
26+
<name>plugins-release</name>
27+
<url>http://repository.jsweet.org/artifactory/plugins-release-local</url>
28+
</pluginRepository>
29+
<pluginRepository>
30+
<snapshots />
31+
<id>jsweet-plugins-snapshots</id>
32+
<name>plugins-snapshot</name>
33+
<url>http://repository.jsweet.org/artifactory/plugins-snapshot-local</url>
34+
</pluginRepository>
35+
</pluginRepositories>
36+
<repositories>
37+
<repository>
38+
<id>jsweet-central</id>
39+
<name>libs-release</name>
40+
<url>http://repository.jsweet.org/artifactory/libs-release-local</url>
41+
</repository>
42+
<repository>
43+
<snapshots />
44+
<id>jsweet-snapshots</id>
45+
<name>libs-snapshot</name>
46+
<url>http://repository.jsweet.org/artifactory/libs-snapshot-local</url>
47+
</repository>
48+
</repositories>
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<version>3.1</version>
54+
<configuration>
55+
<source>1.8</source>
56+
<target>1.8</target>
57+
<fork>true</fork>
58+
</configuration>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.jsweet</groupId>
62+
<artifactId>jsweet-maven-plugin</artifactId>
63+
<version>1.1.0-SNAPSHOT</version>
64+
<configuration>
65+
<outDir>target/js</outDir>
66+
<targetVersion>ES3</targetVersion>
67+
</configuration>
68+
<executions>
69+
<execution>
70+
<id>generate-js</id>
71+
<phase>generate-sources</phase>
72+
<goals>
73+
<goal>jsweet</goal>
74+
</goals>
75+
</execution>
76+
</executions>
77+
</plugin>
78+
</plugins>
79+
<pluginManagement>
80+
<plugins>
81+
<!--This plugin's configuration is used to store Eclipse m2e settings
82+
only. It has no influence on the Maven build itself. -->
83+
<plugin>
84+
<groupId>org.eclipse.m2e</groupId>
85+
<artifactId>lifecycle-mapping</artifactId>
86+
<version>1.0.0</version>
87+
<configuration>
88+
<lifecycleMappingMetadata>
89+
<pluginExecutions>
90+
<pluginExecution>
91+
<pluginExecutionFilter>
92+
<groupId>
93+
org.jsweet
94+
</groupId>
95+
<artifactId>
96+
jsweet-maven-plugin
97+
</artifactId>
98+
<versionRange>
99+
[1.0.0,)
100+
</versionRange>
101+
<goals>
102+
<goal>jsweet</goal>
103+
</goals>
104+
</pluginExecutionFilter>
105+
<action>
106+
<ignore></ignore>
107+
</action>
108+
</pluginExecution>
109+
</pluginExecutions>
110+
</lifecycleMappingMetadata>
111+
</configuration>
112+
</plugin>
113+
</plugins>
114+
</pluginManagement>
115+
</build>
116+
<dependencies>
117+
<dependency>
118+
<groupId>org.jsweet.candies</groupId>
119+
<artifactId>jsweet-core</artifactId>
120+
<version>1.1.0-SNAPSHOT</version>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.jsweet.candies</groupId>
124+
<artifactId>react-global</artifactId>
125+
<version>0.14.0-SNAPSHOT</version>
126+
</dependency>
127+
</dependencies>
128+
</project>
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package examples;
2+
3+
import static def.react.react.Globals.createElement;
4+
import static jsweet.dom.Globals.document;
5+
6+
import def.react.react.HTMLAttributes;
7+
import def.react.react.ReactDOM;
8+
import def.react.react.ReactElement;
9+
10+
public class SimpleExample1 {
11+
12+
static final HTMLAttributes EMPTY = null;
13+
14+
public static void main(String[] args) {
15+
ReactElement<?> rootElement = createElement("div", EMPTY, //
16+
createElement("h1", EMPTY, "Contacts"), //
17+
createElement("ul", EMPTY, //
18+
createElement("li", EMPTY, //
19+
createElement("h2", EMPTY, "James Nelson"), //
20+
createElement("a", new HTMLAttributes() {
21+
{
22+
href = "mailto:[email protected]";
23+
}
24+
}, "[email protected]")), //
25+
createElement("li", EMPTY, //
26+
createElement("h2", EMPTY, "Joe Citizen"), //
27+
createElement("a", new HTMLAttributes() {
28+
{
29+
href = "mailto:[email protected]";
30+
}
31+
32+
33+
ReactDOM.render(rootElement, document.getElementById("react-app"));
34+
}
35+
36+
}
37+
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package examples;
2+
3+
import static def.react.react.Globals.createElement;
4+
import static jsweet.dom.Globals.document;
5+
import static jsweet.util.Globals.$map;
6+
import static jsweet.util.Globals.array;
7+
8+
import def.react.react.HTMLAttributes;
9+
import def.react.react.ReactDOM;
10+
import def.react.react.ReactElement;
11+
import jsweet.lang.Interface;
12+
import jsweet.lang.Optional;
13+
14+
public class SimpleExample2 {
15+
16+
static final HTMLAttributes EMPTY = null;
17+
18+
@Interface
19+
static abstract class Contact {
20+
int key;
21+
String name;
22+
@Optional
23+
String email;
24+
}
25+
26+
public static void main(String[] args) {
27+
Contact[] contacts = { new Contact() {
28+
{
29+
key = 1;
30+
name = "James Nelson";
31+
email = "[email protected]";
32+
}
33+
}, new Contact() {
34+
{
35+
key = 2;
36+
name = "Bob";
37+
}
38+
}, new Contact() {
39+
{
40+
key = 3;
41+
name = "Renaud Pawlak";
42+
email = "[email protected]";
43+
}
44+
}, new Contact() {
45+
{
46+
key = 4;
47+
name = "John Smith";
48+
email = "[email protected]";
49+
}
50+
} };
51+
52+
Object[] listElements = array(array(contacts).filter((contact, __, ___) -> {
53+
return contact.email != null;
54+
})).map((contact, __, ___) -> {
55+
return createElement("li", (HTMLAttributes) $map("key", contact.key), //
56+
createElement("h2", EMPTY, contact.name), //
57+
createElement("a", new HTMLAttributes() {
58+
{
59+
href = "mailto:" + contact.email;
60+
}
61+
}, contact.email));
62+
});
63+
64+
ReactElement<?> rootElement = createElement("div", (HTMLAttributes) $map(), //
65+
createElement("h1", EMPTY, "Contacts"), //
66+
createElement("ul", EMPTY, listElements));
67+
68+
ReactDOM.render(rootElement, document.getElementById("react-app"));
69+
}
70+
71+
}

0 commit comments

Comments
 (0)