Skip to content

Instantly share code, notes, and snippets.

@switchtrue
Last active November 18, 2015 09:22
Show Gist options
  • Save switchtrue/44486585a91752f5b7c5 to your computer and use it in GitHub Desktop.
Save switchtrue/44486585a91752f5b7c5 to your computer and use it in GitHub Desktop.
export function enterRoom(id) {
return {
type: 'ENTER_ROOM',
payload: {
roomId: id
}
};
}
import React from 'react';
import ReactDOM from 'react-dom';
import Router, {Route} from 'react-router';
import App from './components/App';
import reducer from './reducer';
import {compose, createStore} from 'redux';
import {Provider} from 'react-redux';
import {LobbyContainer} from './components/Lobby';
import {RoomContainer} from './components/Room';
import {devTools, persistState} from 'redux-devtools';
import {DevTools, DebugPanel, LogMonitor} from 'redux-devtools/lib/react';
require('./css/reset.css');
require('./css/style.css');
const finalCreateStore = compose(
// Provides support for DevTools:
devTools(),
// Lets you write ?debug_session=<name> in address bar to persist debug sessions
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(createStore);
const store = finalCreateStore(reducer);
import {List, Map, fromJS} from 'immutable';
function enterRoom(state, roomId) {
const availableRooms = state.get('availableRooms');
var roomEntered = availableRooms.map(room => {
if (room.get('_id') == roomId) {
return room;
}
});
var newState = state.set('currentRoom', roomEntered.get(0));
return newState;
}
export default function(state = Map(), action) {
switch (action.type) {
case 'ENTER_ROOM':
return enterRoom(state, action.payload.roomId);
}
return state;
}
import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import {connect} from 'react-redux';
import * as actionCreators from '../actioncreators/Room';
export const Room = React.createClass({
mixins: [PureRenderMixin],
componentWillMount: function() {
this.props.enterRoom(this.props.params.id);
},
render: function() {
return (
<div>
<h1>Room:</h1>
{this.props.room.name}
</div>
);
}
});
function mapStateToProps(state) {
return {
room: state.get('currentRoom')
};
}
export const RoomContainer = connect(
mapStateToProps,
actionCreators
)(Room);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment