Created
January 22, 2019 04:40
-
-
Save shofetim/18a9bcb366c36b4915470eb1d5d234dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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