Skip to content

Instantly share code, notes, and snippets.

View juliensanmartin's full-sized avatar

Julien Sanmartin juliensanmartin

View GitHub Profile
// Callback when the Circle triggers 'onClick' props callback
const _handleClickCircle = (element, clickedDate) => {
// Create a detail object containing the data that is send
// from the react component. Here we send back the current date
const detail = { clickedDate };
// We create then an event 'onClickCircle' and pass this detail object
const event = new CustomEvent('onClickCircle', { detail });
// And dispatch the event
...
// Save in one spot the event's name
private static final String CLICK_CIRCLE_EVENT_TYPE = "onClickCircle";
...
// pass down the element where to attach onClickCircle event
addClickOnCircleEventListener(circleReactElement, CLICK_CIRCLE_EVENT_TYPE, this, true);
...
// Java method using native JS code
package mypackage;
public class ReactEventDetail extends JavaScriptObject {
protected ReactEventDetail() {
// GWT needs this empty constructor
}
public final native String getDate() /*-{ return this.clickedDate; }-*/;
}
// import React and ReactDom that will inject
// our div created in the GWT Widget to our React component
import React from 'react';
import ReactDOM from 'react-dom';
// Circle React component
import { Circle } from 'my-react-shapes';
// An IIFE (Immediately Invoked Function Expression)
// Will runs as soon as it is defined.
package mypackage;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;
import mypackage.ReactEventDetail;
const styleCircle = (color, diameter) => ({
background: color,
width: `${diameter}px`,
height: `${diameter}px`,
borderRadius: '50%'
});
const Circle = ({ diameter, color, onClick }) => (
<div
style={styleCircle(color, diameter)}
package mypackage;
import com.google.gwt.core.client.JavaScriptObject;
public class ReactEventDetail extends JavaScriptObject {
protected ReactEventDetail() {
// GWT needs this empty constructor
}
public final native String getDate() /*-{ return this.currentDate; }-*/;
import React from 'react';
import { getSquareData } from 'square-endpoint';
const styleCircle = (color, diameter) => ({
background: color,
width: `${diameter}px`,
height: `${diameter}px`,
borderRadius: '50%'
});
package mypackage;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;
import mypackage.ReactEventDetail;
@juliensanmartin
juliensanmartin / GWTReactMiddleware.js
Last active February 23, 2019 20:32
JS Middleware sitting between React and GWT
import React from 'react';
import ReactDOM from 'react-dom';
import { Square, Circle } from 'my-react-shapes';
(function(global) {
const renderSquare = (parentDiv, squareId, color, size) => {
const mySquare = (
<Square
squareId={squareId}
color={color}