r98573 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98572‎ | r98573 | r98574 >
Date:21:46, 30 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added length adjustment methods that automatically propagate changes upstream
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js
@@ -1,10 +1,13 @@
22 /**
33 * Creates an es.DocumentModelNode object.
44 *
 5+ * es.DocumentModelNode is a simple wrapper around es.ModelNode, which adds functionality for model
 6+ * nodes to be used as nodes in a space partitioning tree.
 7+ *
58 * @class
69 * @constructor
7 - * @param {Integer} contentLength Length of contents
8 - * @property {Integer} contentLength Length of contents
 10+ * @param {Integer} contentLength Length of content
 11+ * @property {Integer} contentLength Length of content
912 */
1013 es.DocumentModelNode = function( contentLength ) {
1114 // Inheritance
@@ -16,6 +19,51 @@
1720
1821 /* Methods */
1922
 23+/**
 24+ * Sets the content length.
 25+ *
 26+ * @method
 27+ * @param {Integer} contentLength Length of content
 28+ * @throws Invalid content length error if contentLength is less than 0
 29+ */
 30+es.DocumentModelNode.setContentLength = function( contentLength ) {
 31+ if ( contentLength < 0 ) {
 32+ throw 'Invalid content length error. Content length can not be less than 0.';
 33+ }
 34+ var diff = contentLength - this.contentLength;
 35+ this.contentLength = contentLength;
 36+ if ( this.parent ) {
 37+ this.parent.adjustContentLength( diff );
 38+ }
 39+};
 40+
 41+/**
 42+ * Adjust the content length.
 43+ *
 44+ * @method
 45+ * @param {Integer} adjustment Amount to adjust content length by
 46+ * @throws Invalid adjustment error if resulting length is less than 0
 47+ */
 48+es.DocumentModelNode.adjustContentLength = function( adjustment ) {
 49+ this.contentLength += adjustment;
 50+ // Make sure the adjustment was sane
 51+ if ( this.contentLength < 0 ) {
 52+ // Reverse the adjustment
 53+ this.contentLength -= adjustment;
 54+ // Complain about it
 55+ throw 'Invalid adjustment error. Content length can not be less than 0.';
 56+ }
 57+ if ( this.parent ) {
 58+ this.parent.adjustContentLength( adjustment );
 59+ }
 60+};
 61+
 62+/**
 63+ * Gets the content length.
 64+ *
 65+ * @method
 66+ * @returns {Integer} Length of content
 67+ */
2068 es.DocumentModelNode.getContentLength = function() {
2169 return this.contentLength;
2270 };

Status & tagging log