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.
This commit is contained in:
rr- 2016-07-26 21:01:52 +02:00
parent 7022686b77
commit d2a5e1056d
4 changed files with 6 additions and 65 deletions

View file

@ -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) {

View file

@ -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; }

View file

@ -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; }

View file

@ -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; }