Silver Challenge: Caching Messages

Am I correct in thinking that the sessionStorage will persist as long as the websocket connection remains open with npm run dev running in the Terminal? I can reload pages, close the browser window, and even create a new user connection, and old messages will still be loaded.

Here is my MessageStore (sorry for the formatting):

export class MessageStore extends Store {
constructor(key) {
super(sessionStorage);
this.key = key;
}
}

I added this to the end of drawMessage in dom.js, after the scrollIntoView();

var array = $.makeArray(this.$list);
return array;

…to make use of these statements in the ChatApp class in app.js :

let message = new ChatMessage(data);
messageList = this.chatList.drawMessage(message.serialize());
messageStore.set(messageList);

Does this make sense? Is it behaving properly?

(Apologies for the overly-long delay in response!)

As for your challenge solution, I see that you’re creating an array of DOM elements via:

var array = $.makeArray(this.$list);
return array;

Then, you’re storing that array of DOM elements in these two lines:

messageList = this.chatList.drawMessage(message.serialize());
messageStore.set(messageList);

Here are my questions for you:

  • is it your intention to store DOM elements?
  • how are you using those stored DOM elements?