[web] fix bugs

This commit is contained in:
Jason 2016-06-24 01:01:34 +08:00
parent e11d6600be
commit c40ff0277b
7 changed files with 81 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,8 +17,8 @@ const defaultState = {
logId: 0, logId: 0,
visible: false, visible: false,
filters: { debug: false, info: true, web: true }, filters: { debug: false, info: true, web: true },
list: null, list: undefined,
view: null, view: undefined,
} }
export default function reduce(state = defaultState, action) { export default function reduce(state = defaultState, action) {

View File

@ -15,8 +15,8 @@ export const UNKNOWN_CMD = 'FLOWS_UNKNOWN_CMD'
export const FETCH_ERROR = 'FLOWS_FETCH_ERROR' export const FETCH_ERROR = 'FLOWS_FETCH_ERROR'
const defaultState = { const defaultState = {
list: null, list: undefined,
views: null, views: undefined,
} }
export default function reduce(state = defaultState, action) { export default function reduce(state = defaultState, action) {

View File

@ -11,22 +11,27 @@ const defaultState = {
} }
export default function reduce(state = defaultState, action) { export default function reduce(state = defaultState, action) {
if (state.pendingActions && action.type !== RECEIVE) {
return {
...state,
pendingActions: [...state.pendingActions, action]
}
}
switch (action.type) { switch (action.type) {
case SET: case SET:
if (state.pendingActions) {
return {
...state,
pendingActions: [...state.pendingActions, action]
}
}
return { return {
...state, ...state,
data: { ...state.data, [action.id]: null, [action.item.id]: action.item } data: { ...state.data, [action.id]: null, [action.item.id]: action.item }
} }
case CLEAR: case CLEAR:
if (state.pendingActions) {
return {
...state,
pendingActions: [...state.pendingActions, action]
}
}
return { return {
...state, ...state,
data: { ...state.data, [action.id]: null } data: { ...state.data, [action.id]: null }

View File

@ -15,21 +15,23 @@ const defaultState = {
export default function reduce(state = defaultState, action) { export default function reduce(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case UPDATE_FILTER: case UPDATE_FILTER: {
const data = _.values(action.list.data).filter(action.filter).sort(action.sorter) const data = _.values(action.list.data).filter(action.filter).sort(action.sorter)
return { return {
...state, ...state,
data, data,
indexOf: _.fromPairs(data.map((item, index) => [item.id, index])), indexOf: _.fromPairs(data.map((item, index) => [item.id, index])),
} }
}
case UPDATE_SORTER: case UPDATE_SORTER: {
const data = state.data.slice().sort(action.sorter) const data = [...state.data].sort(action.sorter)
return { return {
...state, ...state,
data, data,
indexOf: _.fromPairs(data.map((item, index) => [item.id, index])) indexOf: _.fromPairs(data.map((item, index) => [item.id, index]))
} }
}
case ADD: case ADD:
if (state.indexOf[action.item.id] != null || !action.filter(action.item)) { if (state.indexOf[action.item.id] != null || !action.filter(action.item)) {
@ -49,7 +51,7 @@ export default function reduce(state = defaultState, action) {
...sortedRemove(state, action.id), ...sortedRemove(state, action.id),
} }
case UPDATE: case UPDATE: {
if (state.indexOf[action.item.id] == null) { if (state.indexOf[action.item.id] == null) {
return return
} }
@ -64,14 +66,16 @@ export default function reduce(state = defaultState, action) {
...nextState, ...nextState,
...sortedInsert(nextState, action.item, action.sorter) ...sortedInsert(nextState, action.item, action.sorter)
} }
}
case RECEIVE: case RECEIVE: {
const data = _.values(action.list.data).filter(action.filter).sort(action.sorter) const data = _.values(action.list.data).filter(action.filter).sort(action.sorter)
return { return {
...state, ...state,
data, data,
indexOf: _.fromPairs(data.map((item, index) => [item.id, index])), indexOf: _.fromPairs(data.map((item, index) => [item.id, index])),
} }
}
default: default:
return state return state

View File

@ -2,6 +2,11 @@ import { combineReducers } from 'redux'
import * as viewActions from './utils/view' import * as viewActions from './utils/view'
import main from './views/main.js' import main from './views/main.js'
export const ADD = 'FLOW_VIEWS_ADD'
export const UPDATE = 'FLOW_VIEWS_UPDATE'
export const REMOVE = 'FLOW_VIEWS_REMOVE'
export const RECEIVE = 'FLOW_VIEWS_RECEIVE'
export default combineReducers({ export default combineReducers({
main, main,
}) })

View File

@ -1,10 +1,10 @@
import reduceView, * as viewActions from '../utils/list' import reduceView, * as viewActions from '../utils/list'
import * as viewsActions from '../views' import * as viewsActions from '../views'
export const UPDATE_FILTER = 'MAIN_VIEW_UPDATE_FILTER' export const UPDATE_FILTER = 'FLOW_VIEWS_MAIN_UPDATE_FILTER'
export const UPDATE_SORTER = 'MAIN_VIEW_UPDATE_SORTER' export const UPDATE_SORTER = 'FLOW_VIEWS_MAIN_UPDATE_SORTER'
export const UPDATE_HIGHLIGHT = 'MAIN_VIEW_UPDATE_HIGHLIGHT' export const UPDATE_HIGHLIGHT = 'FLOW_VIEWS_MAIN_UPDATE_HIGHLIGHT'
export const SELECT = 'MAIN_VIEW_SELECT' export const SELECT = 'FLOW_VIEWS_MAIN_SELECT'
const sortKeyFuns = { const sortKeyFuns = {
@ -32,7 +32,7 @@ const defaultState = {
selected: [], selected: [],
filter: null, filter: null,
sorter: { column: null, desc: false }, sorter: { column: null, desc: false },
view: null, view: undefined,
} }
export default function reduce(state = defaultState, action) { export default function reduce(state = defaultState, action) {