| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview This is a data model representin | 6 * @fileoverview This is a data model representin |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 // The include directives are put into Javascript-style comments to prevent | 9 // The include directives are put into Javascript-style comments to prevent |
| 10 // parsing errors in non-flattened mode. The flattener still sees them. | 10 // parsing errors in non-flattened mode. The flattener still sees them. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Returns an array of elements in a selected range. | 121 * Returns an array of elements in a selected range. |
| 122 * @param {number=} opt_from The starting index of the selected range. | 122 * @param {number=} opt_from The starting index of the selected range. |
| 123 * @param {number=} opt_to The ending index of selected range. | 123 * @param {number=} opt_to The ending index of selected range. |
| 124 * @return {Array} An array of elements in the selected range. | 124 * @return {Array} An array of elements in the selected range. |
| 125 */ | 125 */ |
| 126 slice: function(opt_from, opt_to) { | 126 slice: function(opt_from, opt_to) { |
| 127 var arr = this.array_; | 127 var arr = this.array_; |
| 128 return this.indexes_.slice(opt_from, opt_to).map(function(index) { | 128 return this.indexes_.slice(opt_from, opt_to).map(function(index) { |
| 129 return arr[index] | 129 return arr[index]; |
| 130 }); | 130 }); |
| 131 }, | 131 }, |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * This removes and adds items to the model. | 134 * This removes and adds items to the model. |
| 135 * This dispatches a splice event. | 135 * This dispatches a splice event. |
| 136 * This implementation runs sort after splice and creates permutation for | 136 * This implementation runs sort after splice and creates permutation for |
| 137 * the whole change. | 137 * the whole change. |
| 138 * @param {number} index The index of the item to update. | 138 * @param {number} index The index of the item to update. |
| 139 * @param {number} deleteCount The number of items to remove. | 139 * @param {number} deleteCount The number of items to remove. |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 */ | 392 */ |
| 393 createCompareFunction_: function(field) { | 393 createCompareFunction_: function(field) { |
| 394 var compareFunction = | 394 var compareFunction = |
| 395 this.compareFunctions_ ? this.compareFunctions_[field] : null; | 395 this.compareFunctions_ ? this.compareFunctions_[field] : null; |
| 396 var defaultValuesCompareFunction = this.defaultValuesCompareFunction; | 396 var defaultValuesCompareFunction = this.defaultValuesCompareFunction; |
| 397 if (compareFunction) { | 397 if (compareFunction) { |
| 398 return compareFunction; | 398 return compareFunction; |
| 399 } else { | 399 } else { |
| 400 return function(a, b) { | 400 return function(a, b) { |
| 401 return defaultValuesCompareFunction.call(null, a[field], b[field]); | 401 return defaultValuesCompareFunction.call(null, a[field], b[field]); |
| 402 } | 402 }; |
| 403 } | 403 } |
| 404 }, | 404 }, |
| 405 | 405 |
| 406 /** | 406 /** |
| 407 * Creates compare function for given field and direction. | 407 * Creates compare function for given field and direction. |
| 408 * @param {string} field Sort field. | 408 * @param {string} field Sort field. |
| 409 * @param {string} direction Sort direction. | 409 * @param {string} direction Sort direction. |
| 410 * @private | 410 * @private |
| 411 */ | 411 */ |
| 412 sortFunction_: function(field, direction) { | 412 sortFunction_: function(field, direction) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 437 if (a < b) | 437 if (a < b) |
| 438 return -1; | 438 return -1; |
| 439 if (a > b) | 439 if (a > b) |
| 440 return 1; | 440 return 1; |
| 441 return 0; | 441 return 0; |
| 442 } | 442 } |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 return {ArrayDataModel: ArrayDataModel}; | 445 return {ArrayDataModel: ArrayDataModel}; |
| 446 }); | 446 }); |
| OLD | NEW |