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() {
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);
});

View file

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