
When this is merged https://gitlab.com/ligolang/ligo-web-ide/ will be marked as deprecated. This MR does not hook up the webide build to the main CI. The CI integration will come in a subsequent MR for the sake of making review easier.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { Dispatch } from 'redux';
|
|
|
|
import { getErrorMessage, runFunction } from '../../services/api';
|
|
import { AppState } from '../app';
|
|
import { DoneLoadingAction, UpdateLoadingAction } from '../loading';
|
|
import { ChangeOutputAction } from '../result';
|
|
import { CancellableAction } from './cancellable';
|
|
|
|
export class EvaluateFunctionAction extends CancellableAction {
|
|
getAction() {
|
|
return async (dispatch: Dispatch, getState: () => AppState) => {
|
|
const { editor, evaluateFunction: evaluateFunctionState } = getState();
|
|
|
|
dispatch({
|
|
...new UpdateLoadingAction(
|
|
`Evaluating ${evaluateFunctionState.entrypoint} ${evaluateFunctionState.parameters}...`
|
|
)
|
|
});
|
|
|
|
try {
|
|
const result = await runFunction(
|
|
editor.language,
|
|
editor.code,
|
|
evaluateFunctionState.entrypoint,
|
|
evaluateFunctionState.parameters
|
|
);
|
|
if (this.isCancelled()) {
|
|
return;
|
|
}
|
|
dispatch({ ...new ChangeOutputAction(result.output) });
|
|
} catch (ex) {
|
|
if (this.isCancelled()) {
|
|
return;
|
|
}
|
|
dispatch({
|
|
...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`)
|
|
});
|
|
}
|
|
|
|
dispatch({ ...new DoneLoadingAction() });
|
|
};
|
|
}
|
|
}
|