Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created January 22, 2019 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shofetim/18a9bcb366c36b4915470eb1d5d234dc to your computer and use it in GitHub Desktop.
Save shofetim/18a9bcb366c36b4915470eb1d5d234dc to your computer and use it in GitHub Desktop.
var Comment = {
oninit: function (vnode) {
this.comment = vnode.attrs;
},
view: function () {
var item, extra, that;
that = this;
item = this.comment;
if (item.children.length == 0) {
return m("li", {key: item.id}, [
m("p", item.content + item.id)
]);
} else {
return m("li", {key: item.id}, [
m("p", item.content + item.id),
m("ul", item.children.map(function(child) {
return m(Comment, {key: child.id}, child);
}))
]);
}
}
};
var PostView = {
view: function () {
var post = state.posts.current;
return m(
"article", {key: 1},
[
m("h2", post.title),
m(
"ul",
(post.comments || []) .map(function(comment) {
return m(Comment, comment);
})
)
]
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment