Authored by 于良

componentWillUnmount未调用 导致clean操作失败 fix review by 盖剑秋

module.exports = {
dev: {
baseUrl: 'http://192.168.102.206:8095/social',
baseUrl: 'http://192.168.102.31:8095/social',
HTTPTimeout: 30000, //毫秒
},
prd: {
baseUrl: 'http://192.168.102.206:8095/social',
baseUrl: 'http://192.168.102.31:8095/social',
HTTPTimeout: 30000, //毫秒
},
... ...
... ... @@ -296,6 +296,7 @@ export default function community(platform) {
key="SubjectPost"
title="主题帖"
hideNavBar={false}
clone={true}
component={SubjectPostContainer}
initial={false}
rightButtonImage={require('./images/posting/share.png')}
... ... @@ -317,9 +318,9 @@ export default function community(platform) {
<Scene
key='LikeList'
hideNavBar={false}
clone={true}
component={LikeListContainer}
initial={false}
clone={true}
getSceneStyle={(props) => {
return this.navPushStyle(props);
}}
... ...
... ... @@ -36,27 +36,39 @@ const {
} = require('../../constants/actionTypes').default;
export function goToSection(section) {
Actions.Section();
return {
type: GO_TO_SECTION,
payload: section,
};
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'Section';
Actions.Section();
dispatch({
type: GO_TO_SECTION,
payload: {...section, tryToClean},
});
}
}
export function goToPost(id) {
Actions.SubjectPost({postId:id});
return {
type: GO_TO_POST,
payload: id,
};
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'SubjectPost';
Actions.SubjectPost({postId:id});
dispatch({
type: GO_TO_POST,
payload: {id, tryToClean},
});
}
}
export function goToLikeList(postId, likeCount) {
Actions.LikeList({title: `共${likeCount}个赞`});
return {
type: GO_TO_LIKE_LIST,
payload: postId,
};
return (dispatch, getState) => {
let {route} = getState();
let tryToClean = route.lastPopScene == 'LikeList';
Actions.LikeList({title: `共${likeCount}个赞`});
dispatch({
type: GO_TO_LIKE_LIST,
payload: {postId, tryToClean},
});
}
}
export function goToUserOrMe(uid) {
... ... @@ -68,11 +80,7 @@ export function goToUserOrMe(uid) {
type: GO_TO_USER,
});
} else {
Actions.UserThatNotMe();
dispatch({
type: GO_TO_USER_THAT_NOT_ME,
payload: uid,
});
dispatch(goToUserThatNotMe(uid));
}
};
}
... ... @@ -97,14 +105,15 @@ export function goToUser() {
export function goToUserThatNotMe(uid) {
return (dispatch, getState) => {
let {user} = getState();
let {user, route} = getState();
if (user.profile.uid == uid) {
} else {
Actions.UserThatNotMe();
let tryToClean = route.lastPopScene == 'UserThatNotMe';
Actions.UserThatNotMe();
dispatch({
type: GO_TO_USER_THAT_NOT_ME,
payload: uid,
payload: {uid, tryToClean},
});
}
};
... ...
... ... @@ -17,6 +17,7 @@ let InitialState = Record({
sid: -1,
items: List(),
item: item,
cleaned: false,
});
export default InitialState;
... ...
... ... @@ -24,15 +24,26 @@ export default function likeList(state = initialState, action) {
switch (action.type) {
case GO_TO_LIKE_LIST: {
let sid = state.sid + 1;
let currentSid = state.sid;
let newItems = state.items;
let newSid = currentSid;
// componentWillUnmount未调用,导致clean操作未进行
if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) {
newItems = newItems.pop();
newSid = newSid - 1;
}
let sid = newSid + 1;
// 获取新的初始状态item
let item = initialState.item;
// 设置item的value
item = item.set('postId', action.payload);
item = item.set('postId', action.payload.postId);
// items新增item
let newItems = state.items.push(item);
newItems = newItems.push(item);
let nextState = state.set('sid', sid)
.set('items', newItems);
.set('items', newItems)
.set('cleaned', false);
return nextState;
}
... ... @@ -69,7 +80,8 @@ export default function likeList(state = initialState, action) {
if (state.items.size > sid) {
let items = state.items.pop();
let nextState = state.set('sid', sid - 1)
.set('items', items);
.set('items', items)
.set('cleaned', true);
return nextState;
}
}
... ...
... ... @@ -2,6 +2,7 @@ import { ActionConst } from 'react-native-router-flux';
const initialState = {
scene: {},
lastPopScene: '',
};
export default function reducer(state = initialState, action = {}) {
... ... @@ -13,6 +14,12 @@ export default function reducer(state = initialState, action = {}) {
scene: action.scene,
};
case ActionConst.BACK_ACTION:
return {
...state,
lastPopScene: state.scene.sceneKey,
};
// ...other actions
default:
... ...
... ... @@ -54,6 +54,7 @@ let InitialState = Record({
sid: -1,
items: List(),
item: item,
cleaned: false,
});
export default InitialState;
... ...
... ... @@ -10,7 +10,7 @@
* InitialState
*/
import InitialState from './sectionInitialState';
import Immutable, {Map} from 'immutable';
import Immutable, {Map, List} from 'immutable';
const {
SECTION_HEADER_REQUEST,
... ... @@ -46,16 +46,27 @@ export default function sectionReducer(state = initialState, action) {
switch (action.type) {
case GO_TO_SECTION: {
let sid = state.sid + 1;
let currentSid = state.sid;
let newItems = state.items;
let newSid = currentSid;
// componentWillUnmount未调用,导致clean操作未进行
if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) {
newItems = newItems.pop();
newSid = newSid - 1;
}
let sid = newSid + 1;
// 获取新的初始状态item
let item = initialState.item;
// 设置item的value
item = item.set('id', action.payload.id)
.set('name', action.payload.name);
// items新增item
let newItems = state.items.push(item);
let items = newItems.push(item);
let nextState = state.set('sid', sid)
.set('items', newItems);
.set('items', items)
.set('cleaned', false);
return nextState;
}
... ... @@ -172,7 +183,8 @@ export default function sectionReducer(state = initialState, action) {
if (state.items.size > sid) {
let items = state.items.pop();
let nextState = state.set('sid', sid - 1)
.set('items', items);
.set('items', items)
.set('cleaned', true);
return nextState;
}
}
... ...
... ... @@ -68,6 +68,7 @@ let InitialState = Record({
sid: -1,
items: List(),
item: item,
cleaned: false,
});
export default InitialState;
... ...
... ... @@ -56,17 +56,27 @@ export default function postingReducer(state = initialState, action) {
switch (action.type) {
case GO_TO_POST: {
let sid = state.sid + 1;
let currentSid = state.sid;
let newItems = state.items;
let newSid = currentSid;
// componentWillUnmount未调用,导致clean操作未进行
if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) {
newItems = newItems.pop();
newSid = newSid - 1;
}
let sid = newSid + 1;
// 获取新的初始状态item
let item = initialState.item;
// 设置item的value
item = item.set('id', action.payload);
item = item.set('id', action.payload.id);
// items新增item
let newItems = state.items.push(item);
newItems = newItems.push(item);
let nextState = state.set('sid', sid)
.set('items', newItems);
.set('items', newItems)
.set('cleaned', false);
return nextState;
// return state.set('id', action.payload);
}
case SUBJECT_CONTENT_REQUEST: {
... ... @@ -287,7 +297,8 @@ export default function postingReducer(state = initialState, action) {
if (state.items.size > sid) {
let items = state.items.pop();
let nextState = state.set('sid', sid - 1)
.set('items', items);
.set('items', items)
.set('cleaned', true);
return nextState;
}
}
... ...
... ... @@ -32,6 +32,7 @@ let InitialState = Record({
sid: -1,
items: List(),
item: item,
cleaned: false,
});
export default InitialState;
... ...
... ... @@ -28,15 +28,26 @@ export default function userThatNotMe(state = initialState, action) {
switch (action.type) {
case GO_TO_USER_THAT_NOT_ME: {
let sid = state.sid + 1;
let currentSid = state.sid;
let newItems = state.items;
let newSid = currentSid;
// componentWillUnmount未调用,导致clean操作未进行
if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) {
newItems = newItems.pop();
newSid = newSid - 1;
}
let sid = newSid + 1;
// 获取新的初始状态item
let item = initialState.item;
// 设置item的value
item = item.setIn(['profile', 'uid'], action.payload);
item = item.setIn(['profile', 'uid'], action.payload.uid);
// items新增item
let newItems = state.items.push(item);
newItems = newItems.push(item);
let nextState = state.set('sid', sid)
.set('items', newItems);
.set('items', newItems)
.set('cleaned', false);
return nextState;
}
... ... @@ -106,7 +117,8 @@ export default function userThatNotMe(state = initialState, action) {
if (state.items.size > sid) {
let items = state.items.pop();
let nextState = state.set('sid', sid - 1)
.set('items', items);
.set('items', items)
.set('cleaned', true);
return nextState;
}
}
... ...