Permalink
Browse files

annotate view builder

  • Loading branch information...
1 parent 38370be commit 3764f43515951bd3bf43447d4e45395001c5f3b1 @petrjanda committed May 10, 2012
Showing with 35 additions and 15 deletions.
  1. +35 −15 lib/viewBuilder.js
View
@@ -3,6 +3,14 @@ var util = require('util'),
View = require('./view'),
Storage = require('./storage/couchStorage');
+/**
+ View builder is the class responsible for data denormalization for particular
+ view. Its inherits from its basic class for read-only access to its snapshots
+ extending it with set of functions, necessary for successful events decomposition.
+
+ @param {String} Unique view identifier.
+ @param {Array} List of events view is interested in.
+*/
module.exports = ViewBuilder = function(uid, eventNames) {
this.snapshots = true;
@@ -38,22 +46,13 @@ ViewBuilder.prototype.build = function(reload, callback) {
})
}
-ViewBuilder.prototype._updateSnapshot = function(count) {
- var storage = Storage.createStorage();
+/**
+ Apply given event to the view.
- if(count > 0 && this.snapshots) {
- storage.purgeView(this.uid);
- storage.storeView(this);
- }
-}
-
-/*
- * Apply given event to the view.
- *
- * @param {Object} Event object.
- * @param {Function} Callback function.
- * @return {Void}
- */
+ @param {Object} Event object.
+ @param {Function} Callback function.
+ @return {Void}
+*/
// DRY - refactor apply methods from aggregate and view to common place.
ViewBuilder.prototype.apply = function(event, callback) {
var name = event.name.charAt(0).toUpperCase() + event.name.slice(1),
@@ -68,6 +67,27 @@ ViewBuilder.prototype.apply = function(event, callback) {
handler.call(this, event, callback);
}
+/**
+ Update the snapshot with view data.
+
+ @param {Number} Number of messages since last snapshot.
+ @private
+*/
+ViewBuilder.prototype._updateSnapshot = function(count) {
+ var storage = Storage.createStorage();
+
+ if(count > 0 && this.snapshots) {
+ storage.purgeView(this.uid);
+ storage.storeView(this);
+ }
+}
+
+/**
+ Load events increment for the view until the last snapshot was taken. If
+ no snapshot exists, all the events are fetched.
+
+ @param {Function} Callback function accepting view as binding.
+*/
ViewBuilder.prototype._loadEvents = function(callback) {
var self = this;

0 comments on commit 3764f43

Please sign in to comment.