Skip to content

Commit 84fb680

Browse files
ning-yremo5000
authored andcommitted
Add state slice 'academy', minor refactors (#117)
* Make IPlaygroundState extend an IWorkspaceState * Add IAcademyState, move game canvas there
1 parent 12e0eed commit 84fb680

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

src/actions/actionTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface IAction extends ReduxAction {
44
payload: any
55
}
66

7-
/** Game */
7+
/** Academy */
88
export const SAVE_CANVAS = 'SAVE_CANVAS'
99

1010
/** Playground */

src/containers/GameContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = (dispatch: Dis
1414
)
1515

1616
const mapStateToProps: MapStateToProps<StateProps, {}, IState> = state => ({
17-
canvas: state.game.canvas
17+
canvas: state.academy.gameCanvas
1818
})
1919

2020
export default connect(mapStateToProps, mapDispatchToProps)(Game)

src/mocks/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Store } from 'redux'
22
import * as mockStore from 'redux-mock-store'
33

44
import {
5+
defaultAcademy,
56
defaultApplication,
6-
defaultGame,
77
defaultPlayground,
88
defaultSession,
99
IState
@@ -12,8 +12,8 @@ import {
1212
export function mockInitialStore<P>(): Store<IState> {
1313
const createStore = (mockStore as any)()
1414
const state: IState = {
15+
academy: defaultAcademy,
1516
application: defaultApplication,
16-
game: defaultGame,
1717
playground: defaultPlayground,
1818
session: defaultSession
1919
}

src/reducers/game.ts renamed to src/reducers/academy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Reducer } from 'redux'
22

33
import { IAction, SAVE_CANVAS } from '../actions/actionTypes'
4-
import { defaultGame, IGameState } from './states'
4+
import { defaultAcademy, IAcademyState } from './states'
55

6-
export const reducer: Reducer<IGameState> = (state = defaultGame, action: IAction) => {
6+
export const reducer: Reducer<IAcademyState> = (state = defaultAcademy, action: IAction) => {
77
switch (action.type) {
88
case SAVE_CANVAS:
99
return {
1010
...state,
11-
canvas: action.payload
11+
gameCanvas: action.payload
1212
}
1313
default:
1414
return state

src/reducers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { reducer as academy } from './academy'
12
import { reducer as application } from './application'
2-
import { reducer as game } from './game'
33
import { reducer as playground } from './playground'
44
import { reducer as session } from './session'
55

66
export default {
7+
academy,
78
application,
8-
game,
99
playground,
1010
session
1111
}

src/reducers/states.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ import { SourceError } from '../slang/types'
55
import { HistoryHelper } from '../utils/history'
66

77
export interface IState {
8+
readonly academy: IAcademyState
89
readonly application: IApplicationState
9-
readonly game: IGameState
1010
readonly playground: IPlaygroundState
1111
readonly session: ISessionState
1212
}
1313

14+
export interface IAcademyState {
15+
readonly gameCanvas?: HTMLCanvasElement
16+
}
17+
1418
export interface IApplicationState {
1519
readonly title: string
1620
readonly environment: ApplicationEnvironment
1721
}
1822

19-
export const sourceChapters = [1, 2]
20-
const latestSourceChapter = sourceChapters.slice(-1)[0]
21-
22-
export interface IGameState {
23-
readonly canvas?: HTMLCanvasElement
23+
export interface IPlaygroundState extends IWorkspaceState {
24+
readonly queryString?: string
2425
}
2526

26-
export interface IPlaygroundState {
27+
interface IWorkspaceState {
2728
readonly context: Context
2829
readonly editorValue: string
2930
readonly editorWidth: string
3031
readonly isRunning: boolean
31-
readonly queryString?: string
3232
readonly output: InterpreterOutput[]
3333
readonly replValue: string
3434
readonly sourceChapter: number
@@ -37,11 +37,11 @@ export interface IPlaygroundState {
3737
}
3838

3939
export interface ISessionState {
40+
readonly assessmentOverviews?: IAssessmentOverview[]
41+
readonly assessments: Map<number, IAssessment>
4042
readonly announcements?: Announcement[]
4143
readonly historyHelper: HistoryHelper
4244
readonly token?: string
43-
readonly assessments: Map<number, IAssessment>
44-
readonly assessmentOverviews?: IAssessmentOverview[]
4545
readonly username?: string
4646
}
4747

@@ -97,6 +97,9 @@ export enum ApplicationEnvironment {
9797
Test = 'test'
9898
}
9999

100+
export const sourceChapters = [1, 2]
101+
const latestSourceChapter = sourceChapters.slice(-1)[0]
102+
100103
const currentEnvironment = (): ApplicationEnvironment => {
101104
switch (process.env.NODE_ENV) {
102105
case 'development':
@@ -108,15 +111,15 @@ const currentEnvironment = (): ApplicationEnvironment => {
108111
}
109112
}
110113

114+
export const defaultAcademy: IAcademyState = {
115+
gameCanvas: undefined
116+
}
117+
111118
export const defaultApplication: IApplicationState = {
112119
title: 'Cadet',
113120
environment: currentEnvironment()
114121
}
115122

116-
export const defaultGame: IGameState = {
117-
canvas: undefined
118-
}
119-
120123
export const defaultPlayground: IPlaygroundState = {
121124
context: createContext(latestSourceChapter),
122125
editorValue: '',

0 commit comments

Comments
 (0)