Vulcan/packages/nova-comments/lib/views.js

35 lines
936 B
JavaScript
Raw Normal View History

2015-05-08 09:20:58 +09:00
/**
* @summary Comment views are filters used for subscribing to and viewing comments
2015-05-08 09:20:58 +09:00
* @namespace Comments.views
*/
Comments.views = {};
/**
* @summary Add a module to a comment view
2015-05-08 09:20:58 +09:00
* @param {string} viewName - The name of the view
* @param {function} [viewFunction] - The function used to calculate query terms. Takes terms and baseParameters arguments
*/
2015-05-17 15:38:02 +09:00
Comments.views.add = function (viewName, viewFunction) {
2015-05-08 09:20:58 +09:00
Comments.views[viewName] = viewFunction;
};
// will be common to all other view unless specific properties are overwritten
Comments.views.baseParameters = {
options: {
limit: 10
}
};
2015-05-17 15:38:02 +09:00
Comments.views.add("postComments", function (terms) {
2015-05-08 09:20:58 +09:00
return {
selector: {postId: terms.postId},
options: {limit: 0, sort: {score: -1, postedAt: -1}}
2015-05-08 09:20:58 +09:00
};
});
2015-05-17 15:38:02 +09:00
Comments.views.add("userComments", function (terms) {
2015-05-08 09:20:58 +09:00
return {
selector: {userId: terms.userId},
options: {sort: {postedAt: -1}}
2015-05-08 09:20:58 +09:00
};
});