Browse Source

make sure to remove RiotControl events when tags are unmounted

pull/1/head
wes 8 years ago
parent
commit
a8362359ff
  1. 4
      src/scripts/app.tag
  2. 31
      src/scripts/browse.tag
  3. 9
      src/scripts/post.tag

4
src/scripts/app.tag

@ -130,14 +130,14 @@ document.addEventListener("click", function(event) {
} }
}); });
RiotControl.on("postswitch", window.RiotControl.on("postswitch",
(ev) => { (ev) => {
self.update( self.update(
{ {
"currentPage" : ev.title "currentPage" : ev.title
}) })
} }
); );
self.state = { self.state = {
"page" : self.opts.page, "page" : self.opts.page,

31
src/scripts/browse.tag

@ -1,19 +1,19 @@
<browse> <browse>
<div>
<div <div
class="card" style={cardStyle}
class="card content"
each={result in opts.state.results} each={result in opts.state.results}
> >
<div class="card-header"> <div class="card-header">
<a href={"/blog/posts/"+result[1].id}> <a
onclick={openPost(result[1].id)}
>
<h3 class="card-title"> <h3 class="card-title">
{ result[1].title } by { result[1].author } { result[1].title } by { result[1].author }
</h3> </h3>
</a> </a>
</div> </div>
<div class="card-body"> <div class="card-body">
<raw content="{ result[1].content }"></raw>
</div>
</div> </div>
</div> </div>
@ -22,5 +22,26 @@ import './raw.tag';
import route from 'riot-route'; import route from 'riot-route';
var self = this; var self = this;
self.route = route;
self.openPost = (id) => {
return ((ev) => {
console.log(id);
console.log(window.RiotControl.trigger);
});
};
window.RiotControl.on("openpost",
(ev) => {
console.log("caught the event");
}
);
self.cardStyle = {
"margin" : "auto"
};
</script> </script>
</browse> </browse>

9
src/scripts/post.tag

@ -68,11 +68,16 @@ self.swipe = false;
self.start = false; self.start = false;
self.end = false; self.end = false;
RiotControl.on("filtercategory", window.RiotControl.on("filtercategory",
(ev) => { (ev) => {
let category = ev.category.toLowerCase(); let category = ev.category.toLowerCase();
}); });
self.on("unmount", () => {
window.RiotControl.off("filtercategory");
window.RiotControl.off("postswitch");
});
prev(ev) { prev(ev) {
ev.preventDefault(); ev.preventDefault();
self.end = false; self.end = false;
@ -133,7 +138,7 @@ updatePost(postcontent) {
self.nextloading = ""; self.nextloading = "";
self.route("/posts/"+self._id); self.route("/posts/"+self._id);
RiotControl.trigger("postswitch", {"title" : self.title}); window.RiotControl.trigger("postswitch", {"title" : self.title});
self.parent.update(); self.parent.update();

Loading…
Cancel
Save