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.
This commit is contained in:
rr- 2016-08-27 15:39:47 +02:00
parent 63e8683fb8
commit c21309aa35
2 changed files with 12 additions and 7 deletions

View file

@ -7,11 +7,14 @@ class Info {
static get() { static get() {
return api.get('/info') return api.get('/info')
.then(response => { .then(response => {
if (response.featuredPost) { return Promise.resolve(Object.assign(
response.featuredPost = {},
Post.fromResponse(response.featuredPost); response,
} {
return Promise.resolve(response); featuredPost: response.featuredPost ?
Post.fromResponse(response.featuredPost) :
undefined
}));
}, response => { }, response => {
return Promise.reject(response.errorMessage); return Promise.reject(response.errorMessage);
}); });

View file

@ -12,8 +12,10 @@ class TagList extends AbstractList {
`&pageSize=${pageSize}` + `&pageSize=${pageSize}` +
`&fields=${fields.join(',')}`; `&fields=${fields.join(',')}`;
return api.get(url).then(response => { return api.get(url).then(response => {
response.results = TagList.fromResponse(response.results); return Promise.resolve(Object.assign(
return Promise.resolve(response); {},
response,
{results: TagList.fromResponse(response.results)}));
}); });
} }
} }