Switch to redux and webpack

This commit is contained in:
Ken-Håvard Lieng 2015-12-29 00:34:32 +01:00
parent b247287075
commit e389454535
97 changed files with 2722 additions and 2656 deletions

View file

@ -0,0 +1,48 @@
import { Record, List } from 'immutable';
import { UPDATE_PATH } from 'redux-simple-router';
import createReducer from '../util/createReducer';
import * as actions from '../actions';
const Tab = Record({
server: null,
channel: null,
user: null
});
const State = Record({
selected: new Tab(),
history: List()
});
export default createReducer(new State(), {
[actions.SELECT_TAB](state, action) {
const tab = new Tab(action);
return state
.set('selected', tab)
.update('history', history => history.push(tab));
},
[actions.PART](state, action) {
return state.set('history', state.history.filter(tab =>
!(tab.server === action.server && tab.channel === action.channels[0])
));
},
[actions.CLOSE_PRIVATE_CHAT](state, action) {
return state.set('history', state.history.filter(tab =>
!(tab.server === action.server && tab.user === action.nick)
));
},
[actions.DISCONNECT](state, action) {
return state.set('history', state.history.filter(tab => tab.server !== action.server));
},
[UPDATE_PATH](state, action) {
if (action.payload.path.indexOf('.') === -1 && state.selected.server) {
return state.set('selected', new Tab());
}
return state;
}
});