This repository was archived by the owner on Jan 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,9 @@ export const getReducerFromAsyncStorage = createAction(types.GET_REDUCER_FROM_AS
30
30
. catch ( err => {
31
31
console . warn ( err ) ;
32
32
} ) ;
33
+ } , ( resolved , rejected ) => {
34
+ return {
35
+ resolved,
36
+ rejected
37
+ }
33
38
} ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import React, {
4
4
StyleSheet ,
5
5
Text ,
6
6
StatusBar ,
7
+ AppState
7
8
} from 'react-native' ;
8
9
import Toast from '../components/base/Toast' ;
9
10
import * as codePushUtils from '../utils/codePushSync' ;
@@ -12,13 +13,24 @@ import * as codePushUtils from '../utils/codePushSync';
12
13
class Utils extends Component {
13
14
componentDidMount ( ) {
14
15
const { actions} = this . props ;
15
- actions . getReducerFromAsyncStorage ( ) ;
16
+ actions . getReducerFromAsyncStorage ( ( { user} ) => {
17
+ if ( user && user . secret ) {
18
+ actions . getUnreadMessageCount ( ) ;
19
+ }
20
+ } ) ;
21
+ codePushUtils . sync ( ) ;
22
+ AppState . addEventListener ( "change" , ( newState ) => {
23
+ if ( newState === "active" ) {
24
+ codePushUtils . sync ( ) ;
25
+ this . props . user . secret && actions . getUnreadMessageCount ( ) ;
26
+ }
27
+ } ) ;
28
+
16
29
// if (__DEV__) {
17
30
// actions.checkToken('your secretKey', ()=> {
18
31
// actions.toast('登陆成功');
19
32
// });
20
33
// }
21
- codePushUtils . init ( ) ;
22
34
}
23
35
24
36
@@ -51,8 +63,9 @@ const styles = StyleSheet.create({
51
63
52
64
export const LayoutComponent = Utils ;
53
65
export function mapStateToProps ( state ) {
54
- const { utils = { } } = state ;
66
+ const { utils = { } , user } = state ;
55
67
return {
56
- ...utils
68
+ ...utils ,
69
+ user
57
70
}
58
71
}
Original file line number Diff line number Diff line change @@ -21,11 +21,6 @@ export function shouldSync() {
21
21
}
22
22
23
23
24
- export function init ( ) {
24
+ export function sync ( ) {
25
25
shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
26
- AppState . addEventListener ( "change" , ( newState ) => {
27
- if ( newState === "active" ) {
28
- shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
29
- }
30
- } ) ;
31
26
}
You can’t perform that action at this time.
0 commit comments