szurubooru/client/js/models/post_list.js
rr- a697aba1b0 client/general: remove api calls from controls
Introduce some missing models along the way
2016-06-18 10:35:20 +02:00

33 lines
674 B
JavaScript

'use strict';
const events = require('../events.js');
const Post = require('./post.js');
class PostList extends events.EventTarget {
constructor(posts) {
super();
this._list = [];
}
static fromResponse(postsResponse) {
const postList = new PostList();
for (let postResponse of postsResponse) {
postList._list.push(Post.fromResponse(postResponse));
}
return postList;
}
get posts() {
return [...this._list];
}
get length() {
return this._list.length;
}
[Symbol.iterator]() {
return this._list[Symbol.iterator]();
}
}
module.exports = PostList;