r100870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100869‎ | r100870 | r100871 >
Date:20:51, 26 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Cleaned up comment format (to follow newer conventions) and renamed spliceArray to insertIntoArray to make sure it's not confused with normal splice which take varidic arguments
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/es.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/es.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.test.js
@@ -1,6 +1,6 @@
22 module( 'es' );
33
4 -test( 'es.spliceArray', 1, function() {
 4+test( 'es.insertIntoArray', 1, function() {
55 var insert = [], i, arr = ['foo', 'bar'], expected = [];
66 expected[0] = 'foo';
77 for ( i = 0; i < 3000; i++ ) {
@@ -9,6 +9,6 @@
1010 }
1111 expected[3001] = 'bar';
1212
13 - es.spliceArray( arr, 1, insert );
 13+ es.insertIntoArray( arr, 1, insert );
1414 deepEqual( arr, expected, 'splicing 3000 elements into the middle of a 2-element array' );
1515 } );
Index: trunk/parsers/wikidom/lib/hype/es.js
@@ -28,8 +28,8 @@
2929 *
3030 * @static
3131 * @method
32 - * @param dst {Function} Class to extend
33 - * @param src {Function} Base class to use methods from
 32+ * @param {Function} dst Class to extend
 33+ * @param {Function} src Base class to use methods from
3434 */
3535 es.extend = function( dst, src ) {
3636 var base = new src();
@@ -49,9 +49,9 @@
5050 *
5151 * @static
5252 * @method
53 - * @param a {Object} First object to compare
54 - * @param b {Object} Second object to compare
55 - * @param asymmetrical {Boolean} Whether to check only that b contains values from a
 53+ * @param {Object} a First object to compare
 54+ * @param {Object} b Second object to compare
 55+ * @param {Boolean} [asymmetrical] Whether to check only that b contains values from a
5656 * @returns {Boolean} If the objects contain the same values as each other
5757 */
5858 es.compareObjects = function( a, b, asymmetrical ) {
@@ -77,7 +77,7 @@
7878 *
7979 * @static
8080 * @method
81 - * @param source {Array} Array to copy
 81+ * @param {Array} source Array to copy
8282 * @returns {Array} Copy of source array
8383 */
8484 es.copyArray = function( source ) {
@@ -101,7 +101,7 @@
102102 *
103103 * @static
104104 * @method
105 - * @param source {Object} Object to copy
 105+ * @param {Object} source Object to copy
106106 * @returns {Object} Copy of source object
107107 */
108108 es.copyObject = function( source ) {
@@ -126,18 +126,18 @@
127127 *
128128 * @static
129129 * @method
130 - * @param arr {Array} Array to splice insertion into. Will be modified
131 - * @param offset {Number} Offset in arr to splice insertion in at. May be negative; see the 'index' parameter for Array.prototype.splice()
132 - * @param insertion {Array} Array to insert
 130+ * @param {Array} dst Array to splice insertion into. Will be modified
 131+ * @param {Number} offset Offset in arr to splice insertion in at. May be negative; see the 'index' parameter for Array.prototype.splice()
 132+ * @param {Array} src Array of items to insert
133133 */
134 -es.spliceArray = function( arr, offset, insertion ) {
 134+es.insertIntoArray = function( dst, offset, src ) {
135135 // We need to splice insertion in in batches, because of parameter list length limits which vary cross-browser.
136136 // 1024 seems to be a safe batch size on all browsers.
137137 var index = 0, batchSize = 1024;
138 - while ( index < insertion.length ) {
 138+ while ( index < src.length ) {
139139 // Call arr.splice( offset, 0, i0, i1, i2, ..., i1023 );
140 - arr.splice.apply(
141 - arr, [index + offset, 0].concat( insertion.slice( index, index + batchSize ) )
 140+ dst.splice.apply(
 141+ dst, [index + offset, 0].concat( src.slice( index, index + batchSize ) )
142142 );
143143 index += batchSize;
144144 }
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -68,7 +68,7 @@
6969 // Remove the node we are about to insert into from the model tree
7070 nodeParent.splice( index, 1 );
7171 // Perform insert on linear data model
72 - es.spliceArray( this.data, this.cursor, op.data );
 72+ es.insertIntoArray( this.data, this.cursor, op.data );
7373 annotate.call( this, this.cursor + op.data.length );
7474 // Regenerate nodes for the data we've affected
7575 var nodes = es.DocumentModel.createNodesFromData(
@@ -80,7 +80,7 @@
8181 }
8282 } else {
8383 // Perform insert on linear data model
84 - es.spliceArray( this.data, this.cursor, op.data );
 84+ es.insertIntoArray( this.data, this.cursor, op.data );
8585 annotate.call( this, this.cursor + op.data.length );
8686 // Update model tree
8787 node.adjustContentLength( op.data.length );
@@ -796,7 +796,7 @@
797797 // We're inserting content into a structural location,
798798 // so we need to wrap the inserted content in a paragraph.
799799 insertedData = [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ];
800 - es.spliceArray( insertedData, 1, data );
 800+ es.insertIntoArray( insertedData, 1, data );
801801 } else {
802802 // Content being inserted in content is fine, do nothing
803803 }

Status & tagging log