![Jev Björsell](/assets/img/avatar_default.png)
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.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { Dispatch } from 'redux';
|
|
|
|
import { evaluateValue, getErrorMessage } from '../../services/api';
|
|
import { AppState } from '../app';
|
|
import { DoneLoadingAction, UpdateLoadingAction } from '../loading';
|
|
import { ChangeOutputAction } from '../result';
|
|
import { CancellableAction } from './cancellable';
|
|
|
|
export class EvaluateValueAction extends CancellableAction {
|
|
getAction() {
|
|
return async (dispatch: Dispatch, getState: () => AppState) => {
|
|
const { editor, evaluateValue: evaluateValueState } = getState();
|
|
|
|
dispatch({
|
|
...new UpdateLoadingAction(
|
|
`Evaluating "${evaluateValueState.entrypoint}" entrypoint...`
|
|
)
|
|
});
|
|
|
|
try {
|
|
const result = await evaluateValue(
|
|
editor.language,
|
|
editor.code,
|
|
evaluateValueState.entrypoint
|
|
);
|
|
|
|
if (this.isCancelled()) {
|
|
return;
|
|
}
|
|
|
|
dispatch({ ...new ChangeOutputAction(result.code) });
|
|
} catch (ex) {
|
|
if (this.isCancelled()) {
|
|
return;
|
|
}
|
|
dispatch({
|
|
...new ChangeOutputAction(`Error: ${getErrorMessage(ex)}`)
|
|
});
|
|
}
|
|
|
|
dispatch({ ...new DoneLoadingAction() });
|
|
};
|
|
}
|
|
}
|