Skip to content

Commit def9246

Browse files
authored
Revert "Add Source §2 (#35)"
This reverts commit 86eb90a.
1 parent 86eb90a commit def9246

File tree

15 files changed

+84
-150
lines changed

15 files changed

+84
-150
lines changed

src/actions/actionTypes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export const CLEAR_REPL_INPUT = 'CLEAR_REPL_INPUT'
1313
export const CLEAR_REPL_OUTPUT = 'CLEAR_REPL_OUTPUT'
1414
export const CLEAR_CONTEXT = 'CLEAR_CONTEXT'
1515
export const SEND_REPL_INPUT_TO_OUTPUT = 'SEND_REPL_INPUT_TO_OUTPUT'
16-
export const CHAPTER_SELECT = 'CHAPTER_SELECT'
17-
export const CHANGE_CHAPTER = 'CHANGE_CHAPTER'
1816

1917
/** Interpreter */
2018
export const HANDLE_CONSOLE_LOG = 'HANDLE_CONSOLE_LOG'

src/actions/playground.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ChangeEvent } from 'react'
21
import { ActionCreator } from 'redux'
32
import * as actionTypes from './actionTypes'
43

@@ -20,18 +19,6 @@ export const sendReplInputToOutput: ActionCreator<actionTypes.IAction> = (newOut
2019
}
2120
})
2221

23-
export const chapterSelect: ActionCreator<actionTypes.IAction> = (
24-
e: ChangeEvent<HTMLSelectElement>
25-
) => ({
26-
type: actionTypes.CHAPTER_SELECT,
27-
payload: e.currentTarget.value
28-
})
29-
30-
export const changeChapter: ActionCreator<actionTypes.IAction> = (newChapter: number) => ({
31-
type: actionTypes.CHANGE_CHAPTER,
32-
payload: newChapter
33-
})
34-
3522
export const evalEditor = () => ({
3623
type: actionTypes.EVAL_EDITOR
3724
})

src/components/IDE/Control.tsx

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Button, IconName, Intent } from '@blueprintjs/core'
21
import * as React from 'react'
32

4-
import { sourceChapters } from '../../reducers/states'
3+
import { Button, IconName, Intent } from '@blueprintjs/core'
54

65
/**
76
* @property handleEvalEditor - A callback function for evaluation
@@ -11,40 +10,26 @@ export interface IControlProps {
1110
handleEvalEditor: () => void
1211
handleEvalRepl: () => void
1312
handleClearReplOutput: () => void
14-
handleChapterSelect: (e: React.ChangeEvent<HTMLSelectElement>) => void
1513
}
1614

17-
const genericButton = (
18-
label: string,
19-
icon: IconName,
20-
handleClick = () => {},
21-
intent = Intent.NONE,
22-
notMinimal = false
23-
) => (
24-
<Button
25-
onClick={handleClick}
26-
className={(notMinimal ? '' : 'pt-minimal') + ' col-xs-12'}
27-
intent={intent}
28-
icon={icon}
29-
>
30-
{label}
31-
</Button>
32-
)
33-
34-
const chapterSelect = (handleSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {}) => (
35-
<div className="col-xs-4 pt-select pt-select">
36-
<select defaultValue={sourceChapters.slice(-1)[0].toString()} onChange={handleSelect}>
37-
{sourceChapters.map(chap => (
38-
<option key={chap} value={chap}>
39-
{`Source \xa7${chap}`}
40-
</option>
41-
))}
42-
</select>
43-
</div>
44-
)
45-
4615
class Control extends React.Component<IControlProps, {}> {
4716
public render() {
17+
const genericButton = (
18+
label: string,
19+
icon: IconName,
20+
handleClick = () => {},
21+
intent = Intent.NONE,
22+
notMinimal = false
23+
) => (
24+
<Button
25+
onClick={handleClick}
26+
className={(notMinimal ? '' : 'pt-minimal') + ' col-xs-12'}
27+
intent={intent}
28+
icon={icon}
29+
>
30+
{label}
31+
</Button>
32+
)
4833
const runButton = genericButton('Run', 'play', this.props.handleEvalEditor)
4934
const evalButton = genericButton('Eval', 'play', this.props.handleEvalRepl)
5035
const clearButton = genericButton('Clear', 'remove', this.props.handleClearReplOutput)
@@ -53,9 +38,8 @@ class Control extends React.Component<IControlProps, {}> {
5338
<div className="col-xs-2">{runButton}</div>
5439
<div className="col-xs-4">
5540
<div className="row">
56-
{chapterSelect(this.props.handleChapterSelect)}
57-
<div className="col-xs-4">{evalButton}</div>
58-
<div className="col-xs-4">{clearButton}</div>
41+
<div className="col-xs-6">{evalButton}</div>
42+
<div className="col-xs-6">{clearButton}</div>
5943
</div>
6044
</div>
6145
</div>

src/components/IDE/__tests__/Control.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ test('Control renders correctly', () => {
88
const props: IControlProps = {
99
handleEvalEditor: () => {},
1010
handleEvalRepl: () => {},
11-
handleClearReplOutput: () => {},
12-
handleChapterSelect: (e: React.ChangeEvent<HTMLSelectElement>) => {}
11+
handleClearReplOutput: () => {}
1312
}
1413
const app = <Control {...props} />
1514
const tree = shallow(app)

src/components/IDE/__tests__/__snapshots__/Control.tsx.snap

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ exports[`Control renders correctly 1`] = `
99
</div>
1010
<div className=\\"col-xs-4\\">
1111
<div className=\\"row\\">
12-
<div className=\\"col-xs-4 pt-select pt-select\\">
13-
<select defaultValue=\\"2\\" onChange={[Function: handleChapterSelect]}>
14-
<option value={1}>
15-
Source §1
16-
</option>
17-
<option value={2}>
18-
Source §2
19-
</option>
20-
</select>
21-
</div>
22-
<div className=\\"col-xs-4\\">
12+
<div className=\\"col-xs-6\\">
2313
<Blueprint2.Button onClick={[Function: handleEvalRepl]} className=\\"pt-minimal col-xs-12\\" intent=\\"none\\" icon=\\"play\\">
2414
Eval
2515
</Blueprint2.Button>
2616
</div>
27-
<div className=\\"col-xs-4\\">
17+
<div className=\\"col-xs-6\\">
2818
<Blueprint2.Button onClick={[Function: handleClearReplOutput]} className=\\"pt-minimal col-xs-12\\" intent=\\"none\\" icon=\\"remove\\">
2919
Clear
3020
</Blueprint2.Button>

src/containers/IDE/ControlContainer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux'
22
import { bindActionCreators, Dispatch } from 'redux'
33

4-
import { chapterSelect, clearReplOutput, evalEditor, evalRepl } from '../../actions/playground'
4+
import { clearReplOutput, evalEditor, evalRepl } from '../../actions/playground'
55
import Control, { IControlProps } from '../../components/IDE/Control'
66
import { IState } from '../../reducers/states'
77

88
type DispatchProps = Pick<IControlProps, 'handleEvalEditor'> &
99
Pick<IControlProps, 'handleEvalRepl'> &
10-
Pick<IControlProps, 'handleClearReplOutput'> &
11-
Pick<IControlProps, 'handleChapterSelect'>
10+
Pick<IControlProps, 'handleClearReplOutput'>
1211

1312
/** No-op mapStateToProps */
1413
const mapStateToProps: MapStateToProps<{}, {}, IState> = state => ({})
@@ -21,8 +20,7 @@ const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = (dispatch: Dis
2120
{
2221
handleEvalEditor: evalEditor,
2322
handleEvalRepl: evalRepl,
24-
handleClearReplOutput: clearReplOutput,
25-
handleChapterSelect: chapterSelect
23+
handleClearReplOutput: clearReplOutput
2624
},
2725
dispatch
2826
)

src/mocks/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext } from '../slang'
22
import { Context } from '../slang/types'
33

4-
export function mockContext(chapter = 1): Context {
5-
return createContext(chapter)
4+
export function mockContext(): Context {
5+
return createContext()
66
}

src/reducers/playground.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Reducer } from 'redux'
22
import {
3-
CHANGE_CHAPTER,
43
CLEAR_CONTEXT,
54
CLEAR_REPL_INPUT,
65
CLEAR_REPL_OUTPUT,
@@ -42,12 +41,7 @@ export const reducer: Reducer<IPlaygroundState> = (state = defaultPlayground, ac
4241
case CLEAR_CONTEXT:
4342
return {
4443
...state,
45-
context: createContext(state.sourceChapter)
46-
}
47-
case CHANGE_CHAPTER:
48-
return {
49-
...state,
50-
sourceChapter: action.payload
44+
context: createContext()
5145
}
5246
case HANDLE_CONSOLE_LOG:
5347
/* Possible cases:

src/reducers/states.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ export interface IApplicationState {
1111
readonly environment: ApplicationEnvironment
1212
}
1313

14-
export const sourceChapters = [1, 2]
15-
const latestSourceChapter = sourceChapters.slice(-1)[0]
16-
1714
export interface IPlaygroundState {
18-
readonly sourceChapter: number
1915
readonly editorValue: string
2016
readonly replValue: string
2117
readonly context: Context
@@ -91,9 +87,8 @@ export const defaultApplication: IApplicationState = {
9187
}
9288

9389
export const defaultPlayground: IPlaygroundState = {
94-
sourceChapter: latestSourceChapter,
9590
editorValue: '',
9691
replValue: '',
97-
context: createContext(latestSourceChapter),
92+
context: createContext(),
9893
output: []
9994
}

src/sagas/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Context, interrupt, runInContext } from '../slang'
66

77
import * as actions from '../actions'
88
import * as actionTypes from '../actions/actionTypes'
9-
import { showSuccessMessage } from '../notification'
109

1110
function* evalCode(code: string, context: Context) {
1211
const { result, interrupted } = yield race({
@@ -45,20 +44,6 @@ function* interpreterSaga(): SagaIterator {
4544
yield put(actions.sendReplInputToOutput(code))
4645
yield* evalCode(code, context)
4746
})
48-
49-
yield takeEvery(actionTypes.CHAPTER_SELECT, function*(action) {
50-
const newChapter = parseInt((action as actionTypes.IAction).payload, 10)
51-
const oldChapter = yield select((state: IState) => state.playground.sourceChapter)
52-
if (newChapter !== oldChapter) {
53-
yield put(actions.changeChapter(newChapter))
54-
yield put(actions.handleInterruptExecution())
55-
yield put(actions.clearContext())
56-
yield put(actions.clearReplOutput())
57-
yield call(showSuccessMessage, `Switched to Source \xa7${newChapter}`)
58-
} else {
59-
yield undefined
60-
}
61-
})
6247
}
6348

6449
function* mainSaga() {

0 commit comments

Comments
 (0)