feat: Update examples to use single FrontIntpRes

This commit is contained in:
1ambda 2017-01-21 09:18:26 +09:00
parent 5c49e6e3d3
commit c906da6230
7 changed files with 22 additions and 62 deletions

View file

@ -41,13 +41,12 @@ export default class FlowchartInterpreter extends AbstractFrontendInterpreter {
};
/**
* `interpret` method can return multiple results.
* But now, we return just 1 result which is wrapped in an array.
* `interpret` method can return multiple results using `add()`
* but now, we return just 1 result
*/
return [new FrontendInterpreterResult(
DefaultDisplayType.ELEMENT,
return new FrontendInterpreterResult(
callback
)];
);
}
getOption() {

View file

@ -22,14 +22,14 @@
<parent>
<artifactId>zeppelin-examples</artifactId>
<groupId>org.apache.zeppelin</groupId>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>org.apache.zeppelin</groupId>
<artifactId>zeppelin-example-frontend-interpreter-flowchart</artifactId>
<packaging>jar</packaging>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
<name>Zeppelin: Example application - Frontend Flowchart Interpreter</name>
<dependencies>

View file

@ -29,10 +29,15 @@ export default class TranslatorInterpreter extends AbstractFrontendInterpreter {
}
interpret(paragraphText) {
return [new FrontendInterpreterResult(
DefaultDisplayType.TEXT,
this.translate(paragraphText)
)];
/**
* FrontendInterpreterResult
* - accepts not only `string` but also `promise`
* - allows multiple output using the `add()` function
*/
const result = new FrontendInterpreterResult()
.add('%html <h4>Translation From English To Korean</h4>')
.add(this.translate(paragraphText));
return result;
}
translate(text) {

View file

@ -22,14 +22,14 @@
<parent>
<artifactId>zeppelin-examples</artifactId>
<groupId>org.apache.zeppelin</groupId>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>org.apache.zeppelin</groupId>
<artifactId>zeppelin-example-frontend-interpreter-translator</artifactId>
<packaging>jar</packaging>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
<name>Zeppelin: Example application - Frontend Translator Interpreter</name>
<dependencies>

View file

@ -28,14 +28,6 @@ export class AbstractFrontendInterpreter {
this.displayType = displayType;
}
static useInterpret(interpreter) {
return (interpreter.__proto__.hasOwnProperty('interpret'));
}
static useDisplay(interpreter) {
return (interpreter.__proto__.hasOwnProperty('display'));
}
/**
* Consumes text and return multiple interpreter results.
* This method should handle error properly to provide precise error message.
@ -47,20 +39,6 @@ export class AbstractFrontendInterpreter {
/** implement this if you want to add a frontend interpreter */
}
/**
* Consumes text and return a single interpreter result.
* This method should handle error properly to provide precise error message.
*
* Currently, `display` only allows DefaultDisplayType
* as a type of result to avoid to recursive evaluation of display results.
*
* @param paragraphText {string} which doesn't include magic
* @return {FrontendInterpreterResult}
*/
display(paragraphText) {
/** implement this if you want to add a display system */
}
/**
* return magic for this frontend interpreter.
* (e.g `%flowchart`)

View file

@ -245,7 +245,7 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
$scope.paragraph.status = 'FINISHED';
const frontIntpResult = intp.interpret(textWithoutMagic);
const parsed = frontIntpResult.getAllParsedGeneratorsWithTypes(
heliumService.getAvailableFrontendInterpreterDisplay());
heliumService.getAvailableFrontendInterpreters());
parsed.then(resultsMsg => {
$scope.paragraph.results.msg = resultsMsg;
$scope.paragraph.config.tableHide = false;

View file

@ -33,8 +33,6 @@ import {
var heliumBundles = [];
// map for `{ magic: interpreter }`
let frontendIntpWithMagic = {};
// map for `{ displayType: interpreter }`
let frontendIntpWithDisplayType = {};
let visualizationBundles = [];
// load should be promise
@ -47,19 +45,7 @@ import {
heliumBundles.map(b => {
if (b.type === HeliumType.FRONTEND_INTERPRETER) {
const interpreter = new b.class(); // eslint-disable-line new-cap
// add frontend interpreter if `interpret` method is available
if (AbstractFrontendInterpreter.useInterpret(interpreter)) {
frontendIntpWithMagic[interpreter.getMagic()] = interpreter;
}
// add frontend interpreter if `display` method is available
// and its display type is in default display types.
if (AbstractFrontendInterpreter.useDisplay(interpreter) &&
DefaultDisplayType[interpreter.getDisplayType()]) {
frontendIntpWithDisplayType[interpreter.getDisplayType()] = interpreter;
}
frontendIntpWithMagic[interpreter.getMagic()] = interpreter;
} else if (b.type === HeliumType.VISUALIZATION) {
visualizationBundles.push(b);
}
@ -78,20 +64,12 @@ import {
};
/**
* @param displayType {string} e.g `ELEMENT`
* @returns {FrontendInterpreterBase} undefined for non-available displayType
* @returns {Object} map for `{ magic : interpreter }`
*/
this.getFrontendInterpreterUsingDisplayType = function(displayType) {
return frontendIntpWithDisplayType[displayType];
this.getAvailableFrontendInterpreters = function() {
return frontendIntpWithMagic;
};
/**
* @returns {Object}
*/
this.getAvailableFrontendInterpreterDisplay = function() {
return frontendIntpWithDisplayType;
}
this.getVisualizationBundles = function() {
return visualizationBundles;
};