diff options
author | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-20 23:18:57 +0100 |
---|---|---|
committer | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-20 23:25:26 +0100 |
commit | cc3db2982dc22899a9ebea21e8a8dfbfd710f842 (patch) | |
tree | d8e138b300a8d8fded0651ac6be204d8c3342e68 /frontend/src/containers | |
parent | Remove shitty code and move generator stars to the right (diff) | |
download | seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.tar.gz seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.tar.bz2 seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.zip |
DUCKS! Refactor front architecture
Diffstat (limited to 'frontend/src/containers')
-rw-r--r-- | frontend/src/containers/App/actions.js | 5 | ||||
-rw-r--r-- | frontend/src/containers/App/constants.js | 1 | ||||
-rw-r--r-- | frontend/src/containers/App/saga.js | 28 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/actions.js | 16 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/constants.js | 3 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/reducer.js | 13 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/saga.js | 75 | ||||
-rw-r--r-- | frontend/src/containers/HomePage/actions.js | 6 | ||||
-rw-r--r-- | frontend/src/containers/HomePage/saga.js | 5 | ||||
-rw-r--r-- | frontend/src/containers/UserRepo/actions.js | 8 | ||||
-rw-r--r-- | frontend/src/containers/UserRepo/reducer.js | 18 | ||||
-rw-r--r-- | frontend/src/containers/app.js (renamed from frontend/src/containers/App/index.js) | 2 | ||||
-rw-r--r-- | frontend/src/containers/gameBrowser.js (renamed from frontend/src/containers/GameBrowser/index.js) | 0 | ||||
-rw-r--r-- | frontend/src/containers/home.js (renamed from frontend/src/containers/HomePage/index.js) | 4 |
14 files changed, 3 insertions, 181 deletions
diff --git a/frontend/src/containers/App/actions.js b/frontend/src/containers/App/actions.js deleted file mode 100644 index cfb617d5..00000000 --- a/frontend/src/containers/App/actions.js +++ /dev/null @@ -1,5 +0,0 @@ -import { INITIALIZE_WS } from "./constants" - -export const initializeWs = () => ({ - type: INITIALIZE_WS -}) diff --git a/frontend/src/containers/App/constants.js b/frontend/src/containers/App/constants.js deleted file mode 100644 index be31f8cc..00000000 --- a/frontend/src/containers/App/constants.js +++ /dev/null @@ -1 +0,0 @@ -export const INITIALIZE_WS = 'app/INITIALIZE_WS' diff --git a/frontend/src/containers/App/saga.js b/frontend/src/containers/App/saga.js deleted file mode 100644 index 0c212142..00000000 --- a/frontend/src/containers/App/saga.js +++ /dev/null @@ -1,28 +0,0 @@ -import { put, take } from 'redux-saga/effects' -import { eventChannel } from 'redux-saga' - -function createSocketChannel(socket) { - return eventChannel(emit => { - const errorHandler = event => emit(JSON.parse(event.body)) - - const userErrors = socket.subscribe('/user/queue/errors', errorHandler) - - const unsubscribe = () => { - userErrors.unsubscribe() - } - - return unsubscribe - }) -} - -export function* watchOnErrors(socketConnection) { - const { socket } = socketConnection - const socketChannel = createSocketChannel(socket) - - while (true) { - const payload = yield take(socketChannel) - yield put({ type: 'USER_ERROR', payload }) - } -} - -export default watchOnErrors diff --git a/frontend/src/containers/GameBrowser/actions.js b/frontend/src/containers/GameBrowser/actions.js deleted file mode 100644 index 376973b4..00000000 --- a/frontend/src/containers/GameBrowser/actions.js +++ /dev/null @@ -1,16 +0,0 @@ -import { NEW_GAME, JOIN_GAME, CREATE_GAME } from './constants' - -export const newGame = (game) => ({ - type: NEW_GAME, - game -}) - -export const joinGame = (id) => ({ - type: JOIN_GAME, - id -}) - -export const createGame = (name) => ({ - type: CREATE_GAME, - name -}) diff --git a/frontend/src/containers/GameBrowser/constants.js b/frontend/src/containers/GameBrowser/constants.js deleted file mode 100644 index 36f701b7..00000000 --- a/frontend/src/containers/GameBrowser/constants.js +++ /dev/null @@ -1,3 +0,0 @@ -export const NEW_GAME = 'gameBrowser/NEW_GAME' -export const JOIN_GAME = 'gameBrowser/JOIN_GAME' -export const CREATE_GAME = 'gameBrowser/CREATE_GAME' diff --git a/frontend/src/containers/GameBrowser/reducer.js b/frontend/src/containers/GameBrowser/reducer.js deleted file mode 100644 index 4fb3390a..00000000 --- a/frontend/src/containers/GameBrowser/reducer.js +++ /dev/null @@ -1,13 +0,0 @@ -import { Map } from 'immutable' -import { NEW_GAME } from './constants' - -const initialState = Map({}) - -export default function reducer(state = initialState, action) { - switch (action.type) { - case NEW_GAME: - return state.set(action.game.get('id'), action.game) - default: - return state - } -} diff --git a/frontend/src/containers/GameBrowser/saga.js b/frontend/src/containers/GameBrowser/saga.js deleted file mode 100644 index 4cd3d207..00000000 --- a/frontend/src/containers/GameBrowser/saga.js +++ /dev/null @@ -1,75 +0,0 @@ -import { call, put, take } from 'redux-saga/effects' -import { eventChannel } from 'redux-saga' -import { fromJS } from 'immutable' -import { push } from 'react-router-redux' - -import { NEW_GAME, JOIN_GAME, CREATE_GAME } from './constants' -import { newGame, joinGame } from './actions' - -function createSocketChannel(socket) { - return eventChannel(emit => { - const makeHandler = (type) => (event) => { - const response = fromJS(JSON.parse(event.body)) - - emit({ - type, - response - }) - } - - const newGameHandler = makeHandler(NEW_GAME) - const joinGameHandler = makeHandler(JOIN_GAME) - - const newGame = socket.subscribe('/topic/games', newGameHandler) - const joinGame = socket.subscribe('/user/queue/join-game', joinGameHandler) - - const unsubscribe = () => { - newGame.unsubscribe() - joinGame.unsubscribe() - } - - return unsubscribe - }) -} - -export function* watchGames(socketConnection) { - - const { socket } = socketConnection - const socketChannel = createSocketChannel(socket) - - while (true) { - const { type, response } = yield take(socketChannel) - - switch (type) { - case NEW_GAME: - yield put(newGame(response)) - break; - case JOIN_GAME: - yield put(joinGame(response)) - break; - default: - console.error('Unknown type') - } - } -} - -export function* createGame(socketConnection) { - const { name } = yield take(CREATE_GAME) - const { socket } = socketConnection - - socket.send("/app/lobby/create-game", JSON.stringify({ - 'gameName': name, - 'playerName': 'Cesar92' - }), {}) -} - -export function* gameBrowserSaga(socketConnection) { - yield put(push('/lobby')) - - yield [ - call(watchGames, socketConnection), - call(createGame, socketConnection) - ] -} - -export default gameBrowserSaga diff --git a/frontend/src/containers/HomePage/actions.js b/frontend/src/containers/HomePage/actions.js deleted file mode 100644 index e06d6fa2..00000000 --- a/frontend/src/containers/HomePage/actions.js +++ /dev/null @@ -1,6 +0,0 @@ -export const ENTER_GAME = 'homePage/ENTER_GAME' - -export const enterGame = (username) => ({ - type: ENTER_GAME, - username -}) diff --git a/frontend/src/containers/HomePage/saga.js b/frontend/src/containers/HomePage/saga.js deleted file mode 100644 index 24f385c9..00000000 --- a/frontend/src/containers/HomePage/saga.js +++ /dev/null @@ -1,5 +0,0 @@ -function *homeSaga(wsConnection) { - yield console.log('home saga') -} - -export default homeSaga diff --git a/frontend/src/containers/UserRepo/actions.js b/frontend/src/containers/UserRepo/actions.js deleted file mode 100644 index dc06035b..00000000 --- a/frontend/src/containers/UserRepo/actions.js +++ /dev/null @@ -1,8 +0,0 @@ -export const SET_USERNAME = 'homePage/SET_USERNAME' - -export const setUsername = (userName, displayName, index) => ({ - type: SET_USERNAME, - userName, - index, - displayName -}) diff --git a/frontend/src/containers/UserRepo/reducer.js b/frontend/src/containers/UserRepo/reducer.js deleted file mode 100644 index 82960a58..00000000 --- a/frontend/src/containers/UserRepo/reducer.js +++ /dev/null @@ -1,18 +0,0 @@ -import { SET_USERNAME } from './actions' -import { fromJS } from 'immutable' -const initialState = fromJS({ - username: '', - displayName: '', - id: null -}) - -export default (state = initialState, action) => { - switch (action.type) { - case SET_USERNAME: - return state.set('username', action.userName) - .set('displayName', action.displayName) - .set('id', action.index) - default: - return state - } -} diff --git a/frontend/src/containers/App/index.js b/frontend/src/containers/app.js index 70f99b6b..d2245152 100644 --- a/frontend/src/containers/App/index.js +++ b/frontend/src/containers/app.js @@ -10,7 +10,7 @@ import { } from 'rebass' import { Flex } from 'reflexbox' import Modal from '../../components/modals/username' -import GameBrowser from '../GameBrowser' +import GameBrowser from './gameBrowser' class App extends Component { state = { diff --git a/frontend/src/containers/GameBrowser/index.js b/frontend/src/containers/gameBrowser.js index 9deb720b..9deb720b 100644 --- a/frontend/src/containers/GameBrowser/index.js +++ b/frontend/src/containers/gameBrowser.js diff --git a/frontend/src/containers/HomePage/index.js b/frontend/src/containers/home.js index a00f46ae..ce1b69fd 100644 --- a/frontend/src/containers/HomePage/index.js +++ b/frontend/src/containers/home.js @@ -32,9 +32,9 @@ const mapStateToProps = (state) => ({ }) -import { enterGame } from './actions' +import { actions } from '../redux/game' const mapDispatchToProps = { - enterGame + enterGame: actions.enterGame } export default connect(mapStateToProps, mapDispatchToProps)(HomePage) |