-
Notifications
You must be signed in to change notification settings - Fork 1
/
Posts.js
91 lines (65 loc) · 1.81 KB
/
Posts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
define(function(require) {
'use strict';
var Marionette = require('marionette');
var store = require('store');
var Post = Marionette.ItemView.extend({
tagName: 'li',
// FOR DEMO PURPOSES ONLY
// Listen for when a node is added to the DOM, in lieu of "onAttach" event
events: {
'added': 'onAdded',
'click': 'onClick'
},
// FOR DEMO PURPOSES ONLY
attributes: {
ref: ''
},
template: function(props) {
return props.title;
},
// Override to bypass the removal of view.el from the DOM
remove: function() {
this.stopListening();
return this;
},
onRender: function() {
this.$el.data('model', this.model);
},
// FOR DEMO PURPOSES ONLY
onAdded: function(e, node) {
//console.log(this.$el.position('top'));
},
onClick: function() {
this.$el.css({textDecoration: 'line-through'});
}
});
var EmptyView = Marionette.ItemView.extend({
tagName: 'h2',
template: function() {
var state = store.getState();
var selectedReddit = state.selectedReddit;
var postsByReddit = state.postsByReddit;
var selectedPosts = postsByReddit[selectedReddit];
var isFetching = selectedPosts && selectedPosts.isFetching;
if (isFetching) {
return 'Loading...';
} else {
return 'Empty.';
}
}
});
return Marionette.CollectionView.extend({
tagName: 'ul',
childView: Post,
emptyView: EmptyView,
onRender: function() {
var state = store.getState();
var selectedReddit = state.selectedReddit;
var postsByReddit = state.postsByReddit;
var selectedPosts = postsByReddit[selectedReddit];
if (selectedPosts && selectedPosts.isFetching) {
this.$el.css({ opacity: 0.5 });
}
}
});
});