2020-02-28 00:22:43 +04:00
|
|
|
import { Command } from './types';
|
|
|
|
|
2020-02-07 07:04:18 +04:00
|
|
|
export enum ActionType {
|
|
|
|
ChangeOutput = 'result-change-output',
|
|
|
|
ChangeContract = 'result-change-contract'
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResultState {
|
2020-02-28 00:22:43 +04:00
|
|
|
command: Command;
|
2020-02-07 07:04:18 +04:00
|
|
|
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']
|
|
|
|
) {}
|
2020-02-07 07:04:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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']
|
|
|
|
) {}
|
2020-02-07 07:04:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Action = ChangeOutputAction | ChangeContractAction;
|
|
|
|
|
|
|
|
const DEFAULT_STATE: ResultState = {
|
2020-02-28 00:22:43 +04:00
|
|
|
command: Command.Compile,
|
2020-02-07 07:04:18 +04:00
|
|
|
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
|
2020-02-07 07:04:18 +04:00
|
|
|
};
|
|
|
|
case ActionType.ChangeContract:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
output: DEFAULT_STATE.output,
|
2020-02-28 00:22:43 +04:00
|
|
|
contract: action.contract,
|
|
|
|
command: action.command
|
2020-02-07 07:04:18 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
};
|