From f31f67bfec87c97adf9be1ed84160c26cf67cf78 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 10 Sep 2016 15:23:44 +0200 Subject: [PATCH] client/comments: fix adding comment after voting --- client/js/models/post.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/client/js/models/post.js b/client/js/models/post.js index 7125917..7e32143 100644 --- a/client/js/models/post.js +++ b/client/js/models/post.js @@ -7,10 +7,23 @@ const NoteList = require('./note_list.js'); const CommentList = require('./comment_list.js'); const misc = require('../util/misc.js'); +function _syncObservableCollection(target, plainList) { + target.clear(); + for (let item of (plainList || [])) { + target.add(target.constructor._itemClass.fromResponse(item)); + } +} + class Post extends events.EventTarget { constructor() { super(); this._orig = {}; + + for (let obj of [this, this._orig]) { + obj._notes = new NoteList(); + obj._comments = new CommentList(); + } + this._updateFromResponse({}); } @@ -264,9 +277,6 @@ class Post extends events.EventTarget { _flags: [...response.flags || []], _tags: [...response.tags || []], - _notes: NoteList.fromResponse([...response.notes || []]), - _comments: CommentList.fromResponse( - [...response.comments || []]), _relations: [...response.relations || []], _score: response.score, @@ -277,6 +287,11 @@ class Post extends events.EventTarget { _hasCustomThumbnail: response.hasCustomThumbnail, }); + for (let obj of [this, this._orig]) { + _syncObservableCollection(obj._notes, response.notes); + _syncObservableCollection(obj._comments, response.comments); + } + Object.assign(this, map()); Object.assign(this._orig, map()); }