Skip to content

Instantly share code, notes, and snippets.

@jnehlmeier
Last active January 4, 2016 23:18
Show Gist options
  • Save jnehlmeier/c8494b8cffc3f81b23cc to your computer and use it in GitHub Desktop.
Save jnehlmeier/c8494b8cffc3f81b23cc to your computer and use it in GitHub Desktop.
gwt-d3: Workaround Double/Boolean unboxed in GWT 2.8
// package protected because its internal
interface BooleanDatumFunction {
public boolean apply(Element context, Value d, int index);
}
public interface DatumFunction<T> {
public T apply(Element context, Value d, int index);
}
// make it a Java method
public final Selection classed(String classNames, DatumFunction<Boolean> addFunction) {
return classed(classNames, new BooleanDatumFunction() {
public boolean apply(Element context, Value d, int index) {
Boolean ret = addFunction.apply(context, d, index);
return ret == null ? false : ret.booleanValue();
}
});
};
private native final Selection classedImpl(String classNames, BooleanDatumFunction addFunction)/*-{
return this.classed(
classNames,
function(d, i) {
// always returns primitive boolean now
// JSNI Shortcut notation
return addFunction.@BooleanDatumFunction::apply(*)(this,{datum:d},i);
});
}-*/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment