Switch to redux and webpack
This commit is contained in:
parent
b247287075
commit
e389454535
97 changed files with 2722 additions and 2656 deletions
48
client/src/js/reducers/tab.js
Normal file
48
client/src/js/reducers/tab.js
Normal 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;
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue