From dad0dc6a0e7ce9a0958c4ea68c0c2eb691fa6383 Mon Sep 17 00:00:00 2001 From: ning Date: Tue, 19 Jun 2018 12:42:13 +0800 Subject: [PATCH 1/2] Make IPlaygroundState extend an IWorkspaceState --- src/reducers/states.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/reducers/states.ts b/src/reducers/states.ts index 6deecf4d5f..b8bd9ab95b 100644 --- a/src/reducers/states.ts +++ b/src/reducers/states.ts @@ -16,19 +16,19 @@ export interface IApplicationState { readonly environment: ApplicationEnvironment } -export const sourceChapters = [1, 2] -const latestSourceChapter = sourceChapters.slice(-1)[0] - export interface IGameState { readonly canvas?: HTMLCanvasElement } -export interface IPlaygroundState { +export interface IPlaygroundState extends IWorkspaceState { + readonly queryString?: string +} + +interface IWorkspaceState { readonly context: Context readonly editorValue: string readonly editorWidth: string readonly isRunning: boolean - readonly queryString?: string readonly output: InterpreterOutput[] readonly replValue: string readonly sourceChapter: number @@ -97,6 +97,9 @@ export enum ApplicationEnvironment { Test = 'test' } +export const sourceChapters = [1, 2] +const latestSourceChapter = sourceChapters.slice(-1)[0] + const currentEnvironment = (): ApplicationEnvironment => { switch (process.env.NODE_ENV) { case 'development': From 4f0a2b63ab4799afbd45cc632dead824cc68ffca Mon Sep 17 00:00:00 2001 From: ning Date: Tue, 19 Jun 2018 12:51:19 +0800 Subject: [PATCH 2/2] Add IAcademyState, move game canvas there --- src/actions/actionTypes.ts | 2 +- src/containers/GameContainer.ts | 2 +- src/mocks/store.ts | 4 ++-- src/reducers/{game.ts => academy.ts} | 6 +++--- src/reducers/index.ts | 4 ++-- src/reducers/states.ts | 22 +++++++++++----------- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/reducers/{game.ts => academy.ts} (54%) diff --git a/src/actions/actionTypes.ts b/src/actions/actionTypes.ts index 81bc4cacd3..f565903214 100644 --- a/src/actions/actionTypes.ts +++ b/src/actions/actionTypes.ts @@ -4,7 +4,7 @@ export interface IAction extends ReduxAction { payload: any } -/** Game */ +/** Academy */ export const SAVE_CANVAS = 'SAVE_CANVAS' /** Playground */ diff --git a/src/containers/GameContainer.ts b/src/containers/GameContainer.ts index 708622271b..af2336c85d 100644 --- a/src/containers/GameContainer.ts +++ b/src/containers/GameContainer.ts @@ -14,7 +14,7 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Dis ) const mapStateToProps: MapStateToProps = state => ({ - canvas: state.game.canvas + canvas: state.academy.gameCanvas }) export default connect(mapStateToProps, mapDispatchToProps)(Game) diff --git a/src/mocks/store.ts b/src/mocks/store.ts index 51a1a72ef1..6d5b522491 100644 --- a/src/mocks/store.ts +++ b/src/mocks/store.ts @@ -2,8 +2,8 @@ import { Store } from 'redux' import * as mockStore from 'redux-mock-store' import { + defaultAcademy, defaultApplication, - defaultGame, defaultPlayground, defaultSession, IState @@ -12,8 +12,8 @@ import { export function mockInitialStore

(): Store { const createStore = (mockStore as any)() const state: IState = { + academy: defaultAcademy, application: defaultApplication, - game: defaultGame, playground: defaultPlayground, session: defaultSession } diff --git a/src/reducers/game.ts b/src/reducers/academy.ts similarity index 54% rename from src/reducers/game.ts rename to src/reducers/academy.ts index 5ae1af9781..126fc8f9f0 100644 --- a/src/reducers/game.ts +++ b/src/reducers/academy.ts @@ -1,14 +1,14 @@ import { Reducer } from 'redux' import { IAction, SAVE_CANVAS } from '../actions/actionTypes' -import { defaultGame, IGameState } from './states' +import { defaultAcademy, IAcademyState } from './states' -export const reducer: Reducer = (state = defaultGame, action: IAction) => { +export const reducer: Reducer = (state = defaultAcademy, action: IAction) => { switch (action.type) { case SAVE_CANVAS: return { ...state, - canvas: action.payload + gameCanvas: action.payload } default: return state diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 3c490ef772..b5228a7423 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -1,11 +1,11 @@ +import { reducer as academy } from './academy' import { reducer as application } from './application' -import { reducer as game } from './game' import { reducer as playground } from './playground' import { reducer as session } from './session' export default { + academy, application, - game, playground, session } diff --git a/src/reducers/states.ts b/src/reducers/states.ts index b8bd9ab95b..e101d93679 100644 --- a/src/reducers/states.ts +++ b/src/reducers/states.ts @@ -5,21 +5,21 @@ import { SourceError } from '../slang/types' import { HistoryHelper } from '../utils/history' export interface IState { + readonly academy: IAcademyState readonly application: IApplicationState - readonly game: IGameState readonly playground: IPlaygroundState readonly session: ISessionState } +export interface IAcademyState { + readonly gameCanvas?: HTMLCanvasElement +} + export interface IApplicationState { readonly title: string readonly environment: ApplicationEnvironment } -export interface IGameState { - readonly canvas?: HTMLCanvasElement -} - export interface IPlaygroundState extends IWorkspaceState { readonly queryString?: string } @@ -37,11 +37,11 @@ interface IWorkspaceState { } export interface ISessionState { + readonly assessmentOverviews?: IAssessmentOverview[] + readonly assessments: Map readonly announcements?: Announcement[] readonly historyHelper: HistoryHelper readonly token?: string - readonly assessments: Map - readonly assessmentOverviews?: IAssessmentOverview[] readonly username?: string } @@ -111,15 +111,15 @@ const currentEnvironment = (): ApplicationEnvironment => { } } +export const defaultAcademy: IAcademyState = { + gameCanvas: undefined +} + export const defaultApplication: IApplicationState = { title: 'Cadet', environment: currentEnvironment() } -export const defaultGame: IGameState = { - canvas: undefined -} - export const defaultPlayground: IPlaygroundState = { context: createContext(latestSourceChapter), editorValue: '',