ligo/tools/webide/packages/client/src/redux/result.ts

56 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-02-28 00:22:43 +04:00
import { Command } from './types';
export enum ActionType {
ChangeOutput = 'result-change-output',
ChangeContract = 'result-change-contract'
}
export interface ResultState {
2020-02-28 00:22:43 +04:00
command: Command;
output: string;
contract: string;
}
export class ChangeOutputAction {
public readonly type = ActionType.ChangeOutput;
2020-02-28 00:22:43 +04:00
constructor(
public output: ResultState['output'],
public command: ResultState['command']
) {}
}
export class ChangeContractAction {
public readonly type = ActionType.ChangeContract;
2020-02-28 00:22:43 +04:00
constructor(
public contract: ResultState['contract'],
public command: ResultState['command']
) {}
}
type Action = ChangeOutputAction | ChangeContractAction;
const DEFAULT_STATE: ResultState = {
2020-02-28 00:22:43 +04:00
command: Command.Compile,
output: '',
contract: ''
};
export default (state = DEFAULT_STATE, action: Action): ResultState => {
switch (action.type) {
case ActionType.ChangeOutput:
return {
...state,
2020-02-28 00:22:43 +04:00
output: action.output,
command: action.command
};
case ActionType.ChangeContract:
return {
...state,
output: DEFAULT_STATE.output,
2020-02-28 00:22:43 +04:00
contract: action.contract,
command: action.command
};
}
return state;
};