ligo/tools/webide/packages/client/src/redux/dry-run.ts
Jev Björsell c119c44c13
Import webide into main ligo monorepo
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.
2020-02-06 19:04:18 -08:00

67 lines
1.6 KiB
TypeScript

import { ActionType as ExamplesActionType, ChangeSelectedAction as ChangeSelectedExampleAction } from './examples';
export enum ActionType {
ChangeEntrypoint = 'dry-run-change-entrypoint',
ChangeParameters = 'dry-run-change-parameters',
ChangeStorage = 'dry-run-change-storage'
}
export interface DryRunState {
entrypoint: string;
parameters: string;
storage: string;
}
export class ChangeEntrypointAction {
public readonly type = ActionType.ChangeEntrypoint;
constructor(public payload: DryRunState['entrypoint']) {}
}
export class ChangeParametersAction {
public readonly type = ActionType.ChangeParameters;
constructor(public payload: DryRunState['parameters']) {}
}
export class ChangeStorageAction {
public readonly type = ActionType.ChangeStorage;
constructor(public payload: DryRunState['storage']) {}
}
type Action =
| ChangeEntrypointAction
| ChangeParametersAction
| ChangeStorageAction
| ChangeSelectedExampleAction;
const DEFAULT_STATE: DryRunState = {
entrypoint: '',
parameters: '',
storage: ''
};
export default (state = DEFAULT_STATE, action: Action): DryRunState => {
switch (action.type) {
case ExamplesActionType.ChangeSelected:
return {
...state,
...(!action.payload ? DEFAULT_STATE : action.payload.dryRun)
};
case ActionType.ChangeEntrypoint:
return {
...state,
entrypoint: action.payload
};
case ActionType.ChangeParameters:
return {
...state,
parameters: action.payload
};
case ActionType.ChangeStorage:
return {
...state,
storage: action.payload
};
}
return state;
};