From c21309aa351f3b171a6a670f2b3a128075d5581c Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 27 Aug 2016 15:39:47 +0200 Subject: [PATCH] client/models: don't modify API responses API responses are cached internally - if they're modified, they're modified in cache too. This can lead to certain anomalies, that can be easily solved by making object copies. --- client/js/models/info.js | 13 ++++++++----- client/js/models/tag_list.js | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/js/models/info.js b/client/js/models/info.js index ad44f580..d3ea505d 100644 --- a/client/js/models/info.js +++ b/client/js/models/info.js @@ -7,11 +7,14 @@ class Info { static get() { return api.get('/info') .then(response => { - if (response.featuredPost) { - response.featuredPost = - Post.fromResponse(response.featuredPost); - } - return Promise.resolve(response); + return Promise.resolve(Object.assign( + {}, + response, + { + featuredPost: response.featuredPost ? + Post.fromResponse(response.featuredPost) : + undefined + })); }, response => { return Promise.reject(response.errorMessage); }); diff --git a/client/js/models/tag_list.js b/client/js/models/tag_list.js index acd70d59..ec578bbf 100644 --- a/client/js/models/tag_list.js +++ b/client/js/models/tag_list.js @@ -12,8 +12,10 @@ class TagList extends AbstractList { `&pageSize=${pageSize}` + `&fields=${fields.join(',')}`; return api.get(url).then(response => { - response.results = TagList.fromResponse(response.results); - return Promise.resolve(response); + return Promise.resolve(Object.assign( + {}, + response, + {results: TagList.fromResponse(response.results)})); }); } }