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
3030 . catch ( err => {
3131 console . warn ( err ) ;
3232 } ) ;
33+ } , ( resolved , rejected ) => {
34+ return {
35+ resolved,
36+ rejected
37+ }
3338} ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import React, {
44 StyleSheet ,
55 Text ,
66 StatusBar ,
7+ AppState
78} from 'react-native' ;
89import Toast from '../components/base/Toast' ;
910import * as codePushUtils from '../utils/codePushSync' ;
@@ -12,13 +13,24 @@ import * as codePushUtils from '../utils/codePushSync';
1213class Utils extends Component {
1314 componentDidMount ( ) {
1415 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+
1629 // if (__DEV__) {
1730 // actions.checkToken('your secretKey', ()=> {
1831 // actions.toast('登陆成功');
1932 // });
2033 // }
21- codePushUtils . init ( ) ;
2234 }
2335
2436
@@ -51,8 +63,9 @@ const styles = StyleSheet.create({
5163
5264export const LayoutComponent = Utils ;
5365export function mapStateToProps ( state ) {
54- const { utils = { } } = state ;
66+ const { utils = { } , user } = state ;
5567 return {
56- ...utils
68+ ...utils ,
69+ user
5770 }
5871}
Original file line number Diff line number Diff line change @@ -21,11 +21,6 @@ export function shouldSync() {
2121}
2222
2323
24- export function init ( ) {
24+ export function sync ( ) {
2525 shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
26- AppState . addEventListener ( "change" , ( newState ) => {
27- if ( newState === "active" ) {
28- shouldSync ( ) . done ( ( shouldSync ) => shouldSync && codePush . sync ( ) ) ;
29- }
30- } ) ;
3126}
You can’t perform that action at this time.
0 commit comments