-
Notifications
You must be signed in to change notification settings - Fork 5
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
392004f
commit 75183e7
Showing
4 changed files
with
60 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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/de/eddyson/tapestry/react/components/ReactComponent.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,45 @@ | ||
package de.eddyson.tapestry.react.components; | ||
|
||
import org.apache.tapestry5.BindingConstants; | ||
import org.apache.tapestry5.ComponentResources; | ||
import org.apache.tapestry5.MarkupWriter; | ||
import org.apache.tapestry5.annotations.Parameter; | ||
import org.apache.tapestry5.annotations.SupportsInformalParameters; | ||
import org.apache.tapestry5.ioc.annotations.Inject; | ||
import org.apache.tapestry5.json.JSONObject; | ||
import org.apache.tapestry5.services.javascript.JavaScriptSupport; | ||
|
||
@SupportsInformalParameters | ||
public class ReactComponent { | ||
|
||
@Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL) | ||
private String module; | ||
|
||
@Parameter(allowNull = false) | ||
private String elementName = "div"; | ||
|
||
@Inject | ||
private JavaScriptSupport javaScriptSupport; | ||
|
||
@Inject | ||
private ComponentResources componentResources; | ||
|
||
private String clientId; | ||
|
||
void beginRender(final MarkupWriter writer) { | ||
writer.element(elementName); | ||
clientId = javaScriptSupport.allocateClientId(componentResources); | ||
writer.attributes("id", clientId); | ||
} | ||
|
||
void afterRender(final MarkupWriter writer) { | ||
writer.end(); | ||
JSONObject parameters = new JSONObject(); | ||
for (String informalParameterName : componentResources.getInformalParameterNames()) { | ||
parameters.put(informalParameterName, | ||
componentResources.getInformalParameter(informalParameterName, Object.class)); | ||
} | ||
javaScriptSupport.require("eddyson/react/components/reactcomponent").with(module, clientId, parameters); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/META-INF/modules/eddyson/react/components/reactcomponent.coffee
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,6 @@ | ||
define ["react", "require"], (React, require)-> | ||
|
||
(module, clientId, parameters) -> | ||
element = document.getElementById clientId | ||
require [module], (componentClass)-> | ||
React.render (React.createElement componentClass, parameters), element |