Rename state/environment to state/app

This commit is contained in:
Ken-Håvard Lieng 2017-06-07 01:03:35 +02:00
parent 1beb56abcf
commit b0b9904bc1
12 changed files with 93 additions and 79 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect'; import { createStructuredSelector } from 'reselect';
import App from '../components/App'; import App from '../components/App';
import { getConnected } from '../state/app';
import { getChannels } from '../state/channels'; import { getChannels } from '../state/channels';
import { getPrivateChats } from '../state/privateChats'; import { getPrivateChats } from '../state/privateChats';
import { getServers } from '../state/servers'; import { getServers } from '../state/servers';
@ -10,7 +11,7 @@ import { push } from '../util/router';
const mapState = createStructuredSelector({ const mapState = createStructuredSelector({
channels: getChannels, channels: getChannels,
connected: state => state.environment.get('connected'), connected: getConnected,
privateChats: getPrivateChats, privateChats: getPrivateChats,
servers: getServers, servers: getServers,
showTabList: getShowTabList, showTabList: getShowTabList,

View File

@ -1,8 +1,8 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect'; import { createStructuredSelector } from 'reselect';
import Connect from '../components/pages/Connect'; import Connect from '../components/pages/Connect';
import { getConnectDefaults } from '../state/app';
import { join } from '../state/channels'; import { join } from '../state/channels';
import { getConnectDefaults } from '../state/environment';
import { connect as connectServer } from '../state/servers'; import { connect as connectServer } from '../state/servers';
import { select } from '../state/tab'; import { select } from '../state/tab';

View File

@ -1,5 +1,5 @@
import FontFaceObserver from 'fontfaceobserver'; import FontFaceObserver from 'fontfaceobserver';
import { setCharWidth } from '../state/environment'; import { setCharWidth } from '../state/app';
import { stringWidth } from '../util'; import { stringWidth } from '../util';
export default function fonts({ store }) { export default function fonts({ store }) {

View File

@ -1,6 +1,6 @@
import Cookie from 'js-cookie'; import Cookie from 'js-cookie';
import { socket as socketActions } from '../state/actions'; import { socket as socketActions } from '../state/actions';
import { getWrapWidth, setEnvironment } from '../state/environment'; import { getWrapWidth, setConnectDefaults } from '../state/app';
import { addMessages } from '../state/messages'; import { addMessages } from '../state/messages';
import { select, updateSelection } from '../state/tab'; import { select, updateSelection } from '../state/tab';
import { find } from '../util'; import { find } from '../util';
@ -10,7 +10,7 @@ import { replace } from '../util/router';
export default function initialState({ store }) { export default function initialState({ store }) {
const env = JSON.parse(document.getElementById('env').innerHTML); const env = JSON.parse(document.getElementById('env').innerHTML);
store.dispatch(setEnvironment('connect_defaults', env.defaults)); store.dispatch(setConnectDefaults(env.defaults));
if (env.servers) { if (env.servers) {
store.dispatch({ store.dispatch({

View File

@ -1,5 +1,5 @@
import { socketAction } from '../state/actions'; import { socketAction } from '../state/actions';
import { setEnvironment } from '../state/environment'; import { setConnected } from '../state/app';
import { broadcast, inform, print, addMessage, addMessages } from '../state/messages'; import { broadcast, inform, print, addMessage, addMessages } from '../state/messages';
import { select } from '../state/tab'; import { select } from '../state/tab';
import { normalizeChannel } from '../util'; import { normalizeChannel } from '../util';
@ -106,7 +106,7 @@ export default function handleSocket({ socket, store: { dispatch, getState } })
}, },
_connected(connected) { _connected(connected) {
dispatch(setEnvironment('connected', connected)); dispatch(setConnected(connected));
} }
}; };

View File

@ -1,6 +1,6 @@
import { when } from '../util/observe'; import { when } from '../util/observe';
import { measureScrollBarWidth } from '../util'; import { measureScrollBarWidth } from '../util';
import { getCharWidth } from '../state/environment'; import { getCharWidth } from '../state/app';
import { updateMessageHeight } from '../state/messages'; import { updateMessageHeight } from '../state/messages';
const menuWidth = 200; const menuWidth = 200;

View File

@ -1,11 +1,11 @@
export const APP_SET = 'APP_SET';
export const INVITE = 'INVITE'; export const INVITE = 'INVITE';
export const JOIN = 'JOIN'; export const JOIN = 'JOIN';
export const KICK = 'KICK'; export const KICK = 'KICK';
export const PART = 'PART'; export const PART = 'PART';
export const SET_TOPIC = 'SET_TOPIC'; export const SET_TOPIC = 'SET_TOPIC';
export const SET_ENVIRONMENT = 'SET_ENVIRONMENT';
export const INPUT_HISTORY_ADD = 'INPUT_HISTORY_ADD'; export const INPUT_HISTORY_ADD = 'INPUT_HISTORY_ADD';
export const INPUT_HISTORY_DECREMENT = 'INPUT_HISTORY_DECREMENT'; export const INPUT_HISTORY_DECREMENT = 'INPUT_HISTORY_DECREMENT';
export const INPUT_HISTORY_INCREMENT = 'INPUT_HISTORY_INCREMENT'; export const INPUT_HISTORY_INCREMENT = 'INPUT_HISTORY_INCREMENT';

View File

@ -0,0 +1,59 @@
import { Record } from 'immutable';
import createReducer from '../util/createReducer';
import * as actions from './actions';
export const getApp = state => state.app;
export const getConnected = state => state.app.connected;
export const getWrapWidth = state => state.app.wrapWidth;
export const getCharWidth = state => state.app.charWidth;
export const getWindowWidth = state => state.app.windowWidth;
export const getConnectDefaults = state => state.app.connectDefaults;
const ConnectDefaults = Record({
name: '',
address: '',
channels: [],
ssl: false,
password: false
});
const App = Record({
connected: true,
wrapWidth: 0,
charWidth: 0,
windowWidth: 0,
connectDefaults: new ConnectDefaults()
});
export default createReducer(new App(), {
[actions.APP_SET](state, action) {
return state.set(action.key, action.value);
},
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {
return state
.set('wrapWidth', action.wrapWidth)
.set('charWidth', action.charWidth)
.set('windowWidth', action.windowWidth);
}
});
export function appSet(key, value) {
return {
type: actions.APP_SET,
key,
value
};
}
export function setConnected(connected) {
return appSet('connected', connected);
}
export function setCharWidth(width) {
return appSet('charWidth', width);
}
export function setConnectDefaults(defaults) {
return appSet('connectDefaults', new ConnectDefaults(defaults));
}

View File

@ -1,44 +0,0 @@
import { Map } from 'immutable';
import createReducer from '../util/createReducer';
import * as actions from './actions';
export const getEnvironment = state => state.environment;
export const getWrapWidth = state => state.environment.get('wrapWidth');
export const getCharWidth = state => state.environment.get('charWidth');
export const getWindowWidth = state => state.environment.get('windowWidth');
export const getConnectDefaults = state => state.environment.get('connect_defaults');
const initialState = Map({
connected: true
});
export default createReducer(initialState, {
[actions.SET_ENVIRONMENT](state, action) {
return state.set(action.key, action.value);
},
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {
return state
.set('wrapWidth', action.wrapWidth)
.set('charWidth', action.charWidth)
.set('windowWidth', action.windowWidth);
}
});
export function setEnvironment(key, value) {
return {
type: actions.SET_ENVIRONMENT,
key,
value
};
}
export function setWrapWidth(width) {
return setEnvironment('wrapWidth', width);
}
export function setCharWidth(width) {
return setEnvironment('charWidth', width);
}

View File

@ -1,6 +1,6 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import app from './app';
import channels from './channels'; import channels from './channels';
import environment from './environment';
import input from './input'; import input from './input';
import messages from './messages'; import messages from './messages';
import privateChats from './privateChats'; import privateChats from './privateChats';
@ -16,8 +16,8 @@ export const getRouter = state => state.router;
export default function createReducer(router) { export default function createReducer(router) {
return combineReducers({ return combineReducers({
router, router,
app,
channels, channels,
environment,
input, input,
messages, messages,
privateChats, privateChats,

View File

@ -1,7 +1,7 @@
import { List, Map, Record } from 'immutable'; import { List, Map, Record } from 'immutable';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import createReducer from '../util/createReducer'; import createReducer from '../util/createReducer';
import { getWrapWidth, getCharWidth, getWindowWidth } from './environment'; import { getApp } from './app';
import { getSelectedTab } from './tab'; import { getSelectedTab } from './tab';
import { findBreakpoints, messageHeight, linkify, timestamp } from '../util'; import { findBreakpoints, messageHeight, linkify, timestamp } from '../util';
import * as actions from './actions'; import * as actions from './actions';
@ -107,9 +107,7 @@ function initMessage(message, tab, state) {
message.content = from + message.content.slice(7, -1); message.content = from + message.content.slice(7, -1);
} }
const wrapWidth = getWrapWidth(state); const { wrapWidth, charWidth, windowWidth } = getApp(state);
const charWidth = getCharWidth(state);
const windowWidth = getWindowWidth(state);
message.length = message.content.length; message.length = message.content.length;
message.breakpoints = findBreakpoints(message.content); message.breakpoints = findBreakpoints(message.content);