Permalink
Browse files

better annotate view class

  • Loading branch information...
1 parent 9bdc981 commit 38370be92e57e8dc67105ee0c8bbc8f5a7432e4d @petrjanda committed May 10, 2012
Showing with 17 additions and 25 deletions.
  1. +17 −25 lib/view.js
View
42 lib/view.js
@@ -1,31 +1,15 @@
var repo = require('./repository').getInstance(),
Storage = require('./storage/couchStorage');
-/*
- * View is the ultimate way, how to look on your data, wider then the scope
- * of one aggregate. Views take various sets of events, found by type, and
- * compose output data report, to be used as DTO for a client. Its major
- * purpose is to decompose and normalize data from the event stream, so
- * the view queries can run with blazingly fast performance, with no need
- * for additional expensive queries to the database.
- *
- * ## View system architecture
- *
- * The view data itself should be kept in content property. Once the content
- * property is requested, system automatically recognize the action and ask the
- * view storage for current snapshot. Once the data is ready the view might or
- * might not ask for new updates from event stream, apply new events and update
- * the content. As soon as the last step is done, new snapshot is made and
- * stored back to the view database, to optimize query performance. All the
- * snapshooting action is happening in parallel with read operations, or even
- * with other snapshot generators, thus there can be multiple versions of
- * your data in the system (for a reasonably short period).
- *
- * @param {String|Array} Unique view identifier.
- * @param {String|Array} Event, or list of events the view is interested in.
- * @param {Function} Callback to be triggered when view data is loaded to
- * the memory.
- */
+/**
+ ```View``` is the read data representation in your system. It can represent wide
+ range of data well beyond reach of single aggregate. View are denormalized
+ and optimized for reading by simple key fetching without need to do additional
+ complex manipulation and selections.
+
+ @param {String} Unique view identifier.
+ @param {Array} List of events the view is interested in.
+*/
module.exports = View = function(uid, eventNames) {
// Store view unique id.
@@ -41,6 +25,14 @@ module.exports = View = function(uid, eventNames) {
this.lastEvent = 0;
}
+/**
+ Load the view data from the persistancy, using the latest snapshot. Null data is returned
+ if no snapshot is created yet. The load method is exclusively supposed to be used in
+ read requests, fetching the data for usage.
+
+ @param {Function} Callback function to be called with view binding.
+ @returns null
+*/
View.prototype.load = function(callback) {
var self = this,
storage = Storage.createStorage();

0 comments on commit 38370be

Please sign in to comment.