Problem with Chattrbox. Code in book differs from code download for Chapter 18

DOUBLE UPDATE: There’s a useful Errata for this book here for anybody who Googled their way to this post like me :slight_smile: Errata: 1st Edition

UPDATE: Solved some of this. The messages were not displaying on the screen because the line on page 352 that reads $(this.listId).append($messageRow); actually needs to read as follows:

$(this.$list).append($messageRow);

I’m guessing listId was the right name in earlier versions of the code, and wasn’t updated for publication when $list was used (for jquery convention reasons maybe?).

Between that and looking at the ChatMessage code from Chapter 16’s downloaded solutions (not sure why it was there but it DOES correctly handle turning data from a string into a {message: data} I seem to be mostly up and running. And ready to somewhat move on.

If I get this chapter completed and have functioning files that match it, I will post them.

-Mark

I’m having a similar problem towards the end of Chapter 18. The messages will show in the console but not on the screen.

Something is odd on page 351 - where we add the call to ChatForm.init, the code that is removed is NOT the same as the code we already had there from page 342. We had:

let message = new ChatMessage({ message: 'pow!'}); // this gets pow! to the console when the message is logged

This seems like the right way to call the ChatMessage constructor. However on p351 it shows it called as new ChatMessage('pow!'), which doesn’t work, and it replaces it with

let message = new ChatMessage(data) // this logs message as undefined

which follows that same non-working format. (Or if it is supposed to work that way, we’ve skipped a step in handling that “data” value correctly and setting it to “message”.)

I spent a few instructive hours stepping through things with the debugger to be sure that data is actually captured correctly from the form, and that everything else seemed to work as expected. It does. So new ChatMessage({message: data}) works to get things passed all the way to the console, but it seems to break things in other ways later because now the value for data that is passed around is an object, not the simple message string it is used as elsewhere.

I was sure if I stuck with it I’d see what I had done wrong here (usually this works!) but the fact that the downloadable solutions are so different does suggest to me that something is amiss in this chapter. Would love some help!

1 Like