coryhouse / pluralsight-redux-starter

Completed Dev Environment for "Building Applications with React and Redux" on Pluralsight
https://app.pluralsight.com/library/courses/react-redux-react-router-es6/
1.27k stars 911 forks source link

courseApi.saveCourse fails with "TypeError: Cannot read property 'course' of undefined" #3

Closed rafaeltikva closed 8 years ago

rafaeltikva commented 8 years ago

Node version: 5.5.0

npm version: 3.8.9

Operating system: OSX El Capitan, 10.11.2

Command line used: npm start -s

Steps to reproduce:

I'm stuck at this point: https://app.pluralsight.com/player?course=react-redux-react-router-es6&author=cory-house&name=react-redux-react-router-es6-m10&clip=11

For some reason the API call to the mockApi's saveCourse doesn't resolve successfully (it get's rejected and catched with the error mentioned in the subject)

Here's my saveCourse thunk:

export function saveCourse(course) {
    return function(dispatch, getState) { // thunk
        return courseApi.saveCourse(course).then(savedCourse => {

            console.log('returned course:', savedCourse);
            course.id ? dispatch(updateCourseSuccess(savedCourse)) : dispatch(saveCourseSuccess(savedCourse));
            console.log('course dispatched', savedCourse);
        }).catch(error => {
            console.error("An error occured:", error);
            //throw(error);
        });
    };
}

The save itself obviously fails as well. The weird thing is that according to the logs i added, it gets to "returned course", but never reaches "course dispatched"... so it appears the dispatch itself fails...

any ideas?

coryhouse commented 8 years ago

Can you please share your full solution so I can try to reproduce this?

rafaeltikva commented 8 years ago

Sure. I created a repository with the bug i'm facing.

https://github.com/rafaeltikva/pluralsight-redux-starter

Let me know if you need any additional info.

coryhouse commented 8 years ago

I just gave it a look and don't see anything obvious wrong. However, there's a number of extra files with -compiled at the end making it hard to debug.

My suggestion:

  1. Delete all the files with -compiled on the end
  2. Diff the final working example of the course's app with your version.
coryhouse commented 8 years ago

Closing since I haven't heard back - @rafaeltikva, please comment if your issue persists.