c119c44c13
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.
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { ActionType as ExamplesActionType, ChangeSelectedAction as ChangeSelectedExampleAction } from './examples';
|
|
|
|
export enum ActionType {
|
|
ChangeEntrypoint = 'evaluate-function-change-entrypoint',
|
|
ChangeParameters = 'evaluate-function-change-parameters'
|
|
}
|
|
|
|
export interface EvaluateFunctionState {
|
|
entrypoint: string;
|
|
parameters: string;
|
|
}
|
|
|
|
export class ChangeEntrypointAction {
|
|
public readonly type = ActionType.ChangeEntrypoint;
|
|
constructor(public payload: EvaluateFunctionState['entrypoint']) {}
|
|
}
|
|
|
|
export class ChangeParametersAction {
|
|
public readonly type = ActionType.ChangeParameters;
|
|
constructor(public payload: EvaluateFunctionState['parameters']) {}
|
|
}
|
|
|
|
type Action =
|
|
| ChangeEntrypointAction
|
|
| ChangeParametersAction
|
|
| ChangeSelectedExampleAction;
|
|
|
|
const DEFAULT_STATE: EvaluateFunctionState = {
|
|
entrypoint: '',
|
|
parameters: ''
|
|
};
|
|
|
|
export default (
|
|
state = DEFAULT_STATE,
|
|
action: Action
|
|
): EvaluateFunctionState => {
|
|
switch (action.type) {
|
|
case ExamplesActionType.ChangeSelected:
|
|
return {
|
|
...state,
|
|
...(!action.payload ? DEFAULT_STATE : action.payload.evaluateFunction)
|
|
};
|
|
case ActionType.ChangeEntrypoint:
|
|
return {
|
|
...state,
|
|
entrypoint: action.payload
|
|
};
|
|
case ActionType.ChangeParameters:
|
|
return {
|
|
...state,
|
|
parameters: action.payload
|
|
};
|
|
}
|
|
return state;
|
|
};
|