I just started learning mithril, and I'm trying to write a simple frontend which interacts with a RESTful API. However, when I load this in the browser, the browser issues < 30 GET requests to '/posts' per second! I'm not sure if this is an error in my code or how mithril works... How can I make m.request issue a request once throughout the code, or update Post.list arbitrarily?
var Post = {
model: function(data) {
data = data || {};
this.id = m.prop(data.id);
this.text = m.prop(data.text);
this.rating = m.prop(data.rating);
this.created_at = m.prop(data.created_at);
this.url = m.prop(data.url);
this.title = m.prop(data.title);
this.user_id = m.prop(data.user_id);
},
list: function() {
return m.request({
method: "GET",
url: "/posts/",
type: Post.model
});
}
}
var PostIndex = {
controller: function() {
this.posts = Post.list();
},
view: function(ctrl) {
return [
m("table.table", [ m("tbody", [
ctrl.posts().map(function(post) {
return m("tr", [
m("td.heading", { onclick: m.route('/posts/' + post.id) }, [
post.title,
m("small", post.url)
]),
m("td", [ m("small", post.user + ": " + post.created_at) ])
]);
})
])])
];
}
};