Last active
August 29, 2015 14:15
-
-
Save alexander-ae/cff216db327e07c07bea to your computer and use it in GitHub Desktop.
riot + parse
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
<comment-box> | |
<h1>{ opts.title }</h1> | |
<comment-list comments={ comments } /> | |
<comment-form /> | |
this.comments = [] | |
add(comment) { | |
this.comments.push(comment) | |
var Comment = Parse.Object.extend("Comment") | |
var _comment = new Comment() | |
_comment.save(comment) | |
} | |
load() { | |
var self = this | |
var Comment = Parse.Object.extend('Comment') | |
var queryComment = new Parse.Query(Comment) | |
queryComment.find({ | |
success: function (results) { | |
var tmp_comments = [] | |
for (var i = 0; i < results.length; i++) { | |
tmp_comments.push(results[i].toJSON()) | |
} | |
self.update({'comments': tmp_comments}) | |
}, | |
error: function (error) { | |
alert("Error: " + error.code + " " + error.message) | |
} | |
}) | |
} | |
this.load() | |
setInterval(this.load, opts.interval) | |
</comment-box> | |
<comment-form> | |
<form onsubmit={ add }> | |
<input type="text" name="name"> | |
<textarea name="message"></textarea> | |
<input type="submit" value="Publicar"> | |
</form> | |
add(e) { | |
var comment = { | |
name: this.name.value, | |
message: this.message.value | |
} | |
this.parent.add(comment) | |
e.target.reset() | |
} | |
</comment-form> | |
<comment-list> | |
<comment each={ opts.comments } name={ this.name } message={ this.message }/> | |
</comment-list> | |
<comment> | |
<div> | |
<h2>{ opts.name }</h2> | |
<p>{ opts.message }</p> | |
</div> | |
</comment> |
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
<html> | |
<head> | |
<title>Comments</title> | |
<script src="https://www.parsecdn.com/js/parse-1.3.4.min.js"></script> | |
<script src="riot.min.js"></script> | |
</head> | |
<body> | |
<comment-box></comment-box> | |
<script> | |
Parse.initialize("efZ0ix2dmSBRLIXQ2PrRlV2MrtlNHFqxmHR9ndl2", "Eq0ilOfvidmMd6f3h8Qoft0Gvi1CjKOeSSUT64dt"); | |
</script> | |
<script src='comments.js'></script> | |
<script> | |
riot.mount('comment-box', {title: 'Comments', interval: 2500}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment