2015-11-26 22 views
0

我使用的可以在這裏找到包ALT構建應用程序:https://github.com/goatslacker/alt反應本地流量同步調度錯誤

我已經有了退出操作時出現錯誤,因爲同步派遣我想和我不不懂如何使用助焊劑的WAITFOR通話..

這裏是我的代碼:

查看與註銷調用:

import ProfilStore from '../../stores/Profil'; 

class Profil extends Page { 

static route(props, title) { 
    return { 
    component: Profil, 
    title: title || 'Profil', 
    passProps: props 
    }; 
} 

currentProfil() { 
    return this.props.id || MeStore.getState().me.id; 
} 

getProfilState() { 
    return { 
    data: ProfilStore.getState().profils[this.currentProfil()], 
    loading: ProfilStore.loading(this.currentProfil()) 
    }; 
} 

constructor(props) { 
    super(props); 

    this.state = { 
    errors: [] 
    }; 
    this.state = this.getProfilState(); 
} 

onFocus = (event) => { 
    if (event.data.route.component === Profil) { 
    ProfilActions.fetchProfil(this.currentProfil()); 
    } 
} 

componentWillMount() { 
    ProfilStore.listen(this.onProfilsChange); 
    // it can be a tab view or a pushed view 
    if (!this.props.id) { 
    this.props.navigator.navigationContext.addListener('didfocus', this.onFocus); 
    } else { 
    ProfilActions.fetchProfil(this.currentProfil()); 
    } 
} 

componentWillUnmount() { 
    ProfilStore.unlisten(this.onProfilsChange); 
} 

onProfilsChange =() => { 
    this.setState(this.getProfilState()); 
} 

render() { 
    return(
    <TouchableHighlight style={styles.logoutbutton} onPress={LoginActions.logout}> 
     <Text>Logout</Text> 
    </TouchableHighlight> 
); 
} 
} 

LoginActions.js:

'use strict'; 

import alt from '../alt'; 
import LoginUtils from '../utils/login'; 

export class LoginActions { 

    loginSuccess(me) { 
    this.dispatch(me); 
    } 

    loginFailed(err) { 
    this.dispatch(err); 
    } 

    logout() { 
    this.dispatch(); 
    } 

    login() { 
    this.dispatch(); 

    LoginUtils.facebook((err, me) => { 
     if (err) { 
     return this.actions.loginFailed(err); 
     } 

     this.actions.loginSuccess(me); 
    }); 
    } 
} 

export default alt.createActions(LoginActions); 

ProfilStore.js:

import alt from '../alt'; 
import _ from 'lodash'; 
import ProfilActions from '../actions/ProfilActions'; 

export class ProfilStore extends CachedStore { 
constructor() { 

    super(); 

    this.profils = {}; 
    this.status.profilsLoading = []; 
    this.status.profilsLoadingError = {}; 

    this.status.profilDisplaying = []; 
    this.status.profilDisplayingError = {}; 

    this.bindListeners({ 
    handleFetchProfil: ProfilActions.FETCH_PROFIL, 
    handleProfilFetched: ProfilActions.PROFIL_FETCHED, 
    handleProfilFetchFailed: ProfilActions.PROFIL_FETCH_FAILED, 

    handleDisplayProfil: ProfilActions.DISPLAY_PROFIL, 
    handleDisplayProfilFailed: ProfilActions.DISPLAY_PROFIL_FAILED, 
    handleDisplayProfilSuccess: ProfilActions.DISPLAY_PROFIL_SUCCESS 
    }); 
} 

handleDisplayProfil(id) { 
    this.status.profilDisplaying.push(id); 
    delete this.status.profilDisplayingError[id]; 
} 
handleDisplayProfilFailed(data) { 
    _.remove(this.status.profilDisplaying, function(id) { 
    return id === data.id; 
    }); 
    this.status.profilDisplayingError[data.id] = data.err; 
} 
handleDisplayProfilSuccess(idProfil) { 
    _.remove(this.status.profilDisplaying, function(id) { 
    return id === idProfil; 
    }); 
    this.profils[idProfil] = _.extend({}, this.profils[idProfil], {invisible: false}); 
} 
static displayProfilError(id) { 
    return this.getState().status.profilDisplayingError[id]; 
} 
static displayProfilLoading(id) { 
    return _.contains(this.getState().status.profilDisplaying, id); 
} 

handleFetchProfil(id) { 
    this.status.profilsLoading.push(id); 
    delete this.status.profilsLoadingError[id]; 
} 

handleProfilFetched(profil) { 
    this.profils[profil.id] = profil; 
    _.remove(this.status.profilsLoading, function(id) { 
    return id === profil.id; 
    }); 
} 

handleProfilFetchFailed(data) { 
    _.remove(this.status.profilsLoading, function(id) { 
    return id === data.id; 
    }); 
    this.status.profilsLoadingError[data.id] = data.err; 
} 

static error(id) { 
    return this.getState().status.profilsLoadingError[id]; 
} 

static loading(id) { 
    return _.includes(this.getState().status.profilsLoading, id); 
} 

static profil(id) { 
    return this.getState().profils[id]; 
} 

} 
export default alt.createStore(ProfilStore); 

謝謝!

回答

0

骯髒的黑客可能正在將setTimeout(fn,0)環繞在你調用動作調度器的地方。