From d2a5e1056d0f33827e5b6d408cd4851264285557 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 26 Jul 2016 21:01:52 +0200 Subject: [PATCH] client/models: discard field declarations This has important side effect that matters when we check for data changes using _orig dictionary. Previously, _orig was empty (so its members fields were undefiend) whereas the real fields were declared as nulls. This meant that for new entities, the conditions were always true, which is unintended. Now both _orig and the class itself are initially populated with _updateFromResponse which syncs the state between them, removing the problem. --- client/js/models/comment.js | 9 +-------- client/js/models/post.js | 26 ++------------------------ client/js/models/tag.js | 15 ++------------- client/js/models/user.js | 21 +-------------------- 4 files changed, 6 insertions(+), 65 deletions(-) diff --git a/client/js/models/comment.js b/client/js/models/comment.js index d65e13bc..702370c4 100644 --- a/client/js/models/comment.js +++ b/client/js/models/comment.js @@ -6,14 +6,7 @@ const events = require('../events.js'); class Comment extends events.EventTarget { constructor() { super(); - this._id = null; - this._postId = null; - this._text = null; - this._user = null; - this._creationTime = null; - this._lastEditTime = null; - this._score = null; - this._ownScore = null; + this._updateFromResponse({}); } static create(postId) { diff --git a/client/js/models/post.js b/client/js/models/post.js index fb606833..b0d2a47e 100644 --- a/client/js/models/post.js +++ b/client/js/models/post.js @@ -9,30 +9,8 @@ const misc = require('../util/misc.js'); class Post extends events.EventTarget { constructor() { super(); - this._orig = {}; - - this._id = null; - this._type = null; - this._mimeType = null; - this._creationTime = null; - this._user = null; - this._safety = null; - this._contentUrl = null; - this._thumbnailUrl = null; - this._canvasWidth = null; - this._canvasHeight = null; - this._fileSize = null; - - this._flags = []; - this._tags = []; - this._notes = []; - this._comments = []; - this._relations = []; - - this._score = null; - this._favoriteCount = null; - this._ownScore = null; - this._ownFavorite = null; + this._orig = {}; + this._updateFromResponse({}); } get id() { return this._id; } diff --git a/client/js/models/tag.js b/client/js/models/tag.js index 32db9647..c07f4952 100644 --- a/client/js/models/tag.js +++ b/client/js/models/tag.js @@ -7,19 +7,8 @@ const misc = require('../util/misc.js'); class Tag extends events.EventTarget { constructor() { super(); - this._orig = {}; - - this._origName = null; - this._category = null; - this._description = null; - - this._names = []; - this._suggestions = []; - this._implications = []; - - this._postCount = null; - this._creationTime = null; - this._lastEditTime = null; + this._orig = {}; + this._updateFromResponse({}); } get names() { return this._names; } diff --git a/client/js/models/user.js b/client/js/models/user.js index 4ebcac0e..0b458660 100644 --- a/client/js/models/user.js +++ b/client/js/models/user.js @@ -6,26 +6,7 @@ const events = require('../events.js'); class User extends events.EventTarget { constructor() { super(); - this._name = null; - this._rank = null; - this._email = null; - this._avatarStyle = null; - this._avatarUrl = null; - this._creationTime = null; - this._lastLoginTime = null; - this._commentCount = null; - this._favoritePostCount = null; - this._uploadedPostCount = null; - this._likedPostCount = null; - this._dislikedPostCount = null; - - this._origName = null; - this._origEmail = null; - this._origRank = null; - this._origAvatarStyle = null; - - this._password = null; - this._avatarContent = null; + this._updateFromResponse({}); } get name() { return this._name; }