2016-08-27 11 views
5

मैं रेडक्स पर प्रतिक्रिया करने के लिए नया हूं। बस रेडक्स सागा को आजमाएं और कुछ त्रुटि संदेशों का सामना करना जो मैं समझ नहीं पाया। यह मेरा rootSaga है:रेडक्स गाथा "रूटसागा रद्द कर दिया गया है"

import { takeEvery } from 'redux-saga'; 
import { AUTH_LOAD_SUCCESS,AUTH_SIGNUP,AUTH_SIGNIN,AUTH_SIGNOUT } from '../reducers/auth'; 
import { receiveAuth,signUp,signIn,onSignOut } from './auth'; 

export default function* rootSaga(){ 
    yield [ 
     takeEvery('AUTH_LOAD_SUCCESS', receiveAuth), 
     takeEvery('AUTH_SIGNUP', signUp), 
     takeEvery('AUTH_SIGNOUT',onSignOut), 
     takeEvery('AUTH_SIGNIN', signIn)   
] 

}

साइन इन करें और साइन अप मेरे लिए पूरी तरह से काम करता है, लेकिन उसके बाद मैं अपने कंसोल में निम्न त्रुटि संदेश मिलता है। तो फिर भी मैं रेडक्स-सागा का उपयोग करके लॉग इन कर सकता हूं लेकिन त्रुटि संदेशों के अनुसार सागा को "रद्द" होने के कारण संभवतः काम करने के लिए साइनऑट नहीं मिल सकता है। क्या कोई मुझे बता सकता है कि क्या हो रहा है? धन्यवाद

bundle.js:79457 uncaught at check call: argument fn is undefinedlog @ bundle.js:79457 
bundle.js:79457 rootSaga has been cancelled 
bundle.js:79457 uncaught at rootSaga 
at rootSaga 
at signIn 
Error: call: argument fn is undefined 
    at check (http://127.0.0.1:3000/dist/bundle.js:79313:12) 
    at getFnCallDesc (http://127.0.0.1:3000/dist/bundle.js:80311:21) 
    at call (http://127.0.0.1:3000/dist/bundle.js:80336:24) 
    at signIn$ (http://127.0.0.1:3000/dist/bundle.js:81213:47) 
    at tryCatch (http://127.0.0.1:3000/dist/bundle.js:7893:41) 
    at GeneratorFunctionPrototype.invoke [as _invoke] (http://127.0.0.1:3000/dist/bundle.js:8167:23) 
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (http://127.0.0.1:3000/dist/bundle.js:7926:22) 
    at next (http://127.0.0.1:3000/dist/bundle.js:79727:28) 
    at currCb (http://127.0.0.1:3000/dist/bundle.js:79801:8) 
    at http://127.0.0.1:3000/dist/bundle.js:79904:17 

अतिरिक्त जानकारी:

sagas/auth.js 
import 'babel-polyfill'; 
import fetch from 'isomorphic-fetch' 
import { browserHistory } from 'react-router'; 
import cookie from 'react-cookie'; 
import { put,call,select } from 'redux-saga/effects'; 
import { requestSignUp,requestSignIn,requestSignOut,receiveUser,receiveSignIn,receiveSignOut } from '../reducers/auth' 



export function* onSignOut(){ 

/////////////////ignore this for the moment/////// 
console.log("ffss") 

} 

export function* receiveAuth() { 
    const user = cookie.load('username'); 

    yield put(receiveAuth(user)); 
    } 

export function* signUp(action) { 
    yield put(requestSignUp()) 
    try { 
     const response = yield call(fetch,'/api/sign_up', { 
        method:'POST', 
        headers:{'Accept': 'application/json', 'Content-Type': 'application/json'}, 
        body: JSON.stringify(action.payload) /////action.payload contains {username:'aa',password:'aa'} 
        }) 
     if(response.ok){ 
      yield call(cookie.save,'username', action.payload.username) 
      yield put(receiveUser(action.payload.username)) 
      yield call(browserHistory.push('/chat')) 
     } 
    } catch (err){ 
     throw err 
     }  
} 

export function* signIn(action) { console.log("hi") 
    yield put(requestSignIn()) 
    try { 

     const response = yield call(fetch,'/api/sign_in', { 
       method:'POST', 
       headers:{'Accept': 'application/json', 'Content-Type': 'application/json'}, 
       body: JSON.stringify(action.payload) /////action.payload contains {username:'aa',password:'aa'} 
       }) 


     if(response.ok){ 
      yield call(cookie.save,'username',action.payload.username) 
      yield put(receiveSignIn(action.payload)) 
      yield call(browserHistory.push('/chat')) 
     } 
    } catch (err){ 
     throw err 
     } 
} 

मुझे लगता है कि मैं एक दूसरा तर्क में डालने के लिए कॉल करने के लिए उम्मीद कर रहा हूँ लेकिन जब मैं अशक्त कोडित यानी yield call(browserHistory.push('/chat'),null) मैं अभी भी त्रुटियों मिल

uncaught at signIn call: argument fn is undefined 
uncaught at check call: argument fn is undefined 

साथ ही, मेरा प्राप्तकर्ता इस संदेश को वापस कर रहा है:

uncaught at rootSaga 
at rootSaga 
at receiveAuth 
Error: Actions must be plain objects. Use custom middleware for async actions. 
+0

आप साइन-इन गाथा के लिए कोड पोस्ट कर सकते हैं? ऐसा लगता है कि अपवाद को –

उत्तर

11

त्रुटि yield call(somefunc, ...) से है जो आपके पास signIn गाथा के अंदर है। यह कहता है कि someFunc (जो भी आपके कोड में है) अनिर्धारित है। तो अगर आप की जाँच करनी चाहिए अगर आप समारोह नाम गलत वर्तनी वाले या शायद अपने को परिभाषित मॉड्यूल से निर्यात करने के लिए छोड़े गए नहीं किया

संपादित

मैंने देखा है कि आप इस

yield call(browserHistory.push('/chat'),null) 
तरह browserHistory.push फ़ंक्शन को कॉल करें

आपको फ़ंक्शन को स्वयं कॉल नहीं करना चाहिए, लेकिन कार्य को स्वयं (और अंततः इस संदर्भ) के साथ सागा

yield apply(browserHistory, browserHistory.push, ['/chat']) 
पर कार्य प्रदान करना चाहिए

मैं apply Effect जो बुला एक this संदर्भ के साथ तरीकों की अनुमति देता है का उपयोग कर रहा (संदर्भ एक 1st तर्क के रूप में प्रदान की जाती है)

+0

फेंक दिया जा रहा है दो समस्याएं हैं जो समस्या पैदा कर सकती हैं। कृपया जो अतिरिक्त जानकारी मैंने जोड़ा है उसे देखें। क्या आप कृपया मुझे बता सकते हैं कि उन्हें कैसे सुधार किया जाना चाहिए? – mtangula

+0

पूरी तरह से काम करता है, धन्यवाद! बीटीडब्ल्यू मुझे लगता है कि आप नारुतो – mtangula

+0

ओह यियीवीस के प्रशंसक हैं! –

संबंधित मुद्दे