Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/array_data_model.js

Issue 7799034: Call prepareSort before any sorting happens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 cr.define('cr.ui', function() { 9 cr.define('cr.ui', function() {
10 const EventTarget = cr.EventTarget; 10 const EventTarget = cr.EventTarget;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 var arr = this.array_; 142 var arr = this.array_;
143 143
144 // TODO(arv): Maybe unify splice and change events? 144 // TODO(arv): Maybe unify splice and change events?
145 var spliceEvent = new Event('splice'); 145 var spliceEvent = new Event('splice');
146 spliceEvent.index = index; 146 spliceEvent.index = index;
147 spliceEvent.removed = arr.slice(index, index + deleteCount); 147 spliceEvent.removed = arr.slice(index, index + deleteCount);
148 spliceEvent.added = Array.prototype.slice.call(arguments, 2); 148 spliceEvent.added = Array.prototype.slice.call(arguments, 2);
149 149
150 var rv = arr.splice.apply(arr, arguments); 150 var rv = arr.splice.apply(arr, arguments);
151 var self = this;
151 152
152 // if sortStatus.field is null, this restores original order. 153 // if sortStatus.field is null, this restores original order.
153 var sortPermutation = this.doSort_(this.sortStatus.field, 154 this.prepareSort(this.sortStatus.field, function() {
154 this.sortStatus.direction); 155 var sortPermutation = self.doSort_(self.sortStatus.field,
155 if (sortPermutation) { 156 self.sortStatus.direction);
156 var splicePermutation = deletePermutation.map(function(element) { 157 if (sortPermutation) {
157 return element != -1 ? sortPermutation[element] : -1; 158 var splicePermutation = deletePermutation.map(function(element) {
158 }); 159 return element != -1 ? sortPermutation[element] : -1;
159 this.dispatchPermutedEvent_(splicePermutation); 160 });
160 } else { 161 self.dispatchPermutedEvent_(splicePermutation);
161 this.dispatchPermutedEvent_(deletePermutation); 162 } else {
162 } 163 self.dispatchPermutedEvent_(deletePermutation);
164 }
163 165
164 this.dispatchEvent(spliceEvent); 166 self.dispatchEvent(spliceEvent);
167 });
168
165 return rv; 169 return rv;
166 }, 170 },
167 171
168 /** 172 /**
169 * Appends items to the end of the model. 173 * Appends items to the end of the model.
170 * 174 *
171 * This dispatches a splice event. 175 * This dispatches a splice event.
172 * 176 *
173 * @param {...*} The items to append. 177 * @param {...*} The items to append.
174 * @return {number} The new length of the model. 178 * @return {number} The new length of the model.
(...skipping 15 matching lines...) Expand all
190 updateIndex: function(index) { 194 updateIndex: function(index) {
191 if (index < 0 || index >= this.length) 195 if (index < 0 || index >= this.length)
192 throw Error('Invalid index, ' + index); 196 throw Error('Invalid index, ' + index);
193 197
194 // TODO(arv): Maybe unify splice and change events? 198 // TODO(arv): Maybe unify splice and change events?
195 var e = new Event('change'); 199 var e = new Event('change');
196 e.index = index; 200 e.index = index;
197 this.dispatchEvent(e); 201 this.dispatchEvent(e);
198 202
199 if (this.sortStatus.field) { 203 if (this.sortStatus.field) {
200 var sortPermutation = this.doSort_(this.sortStatus.field, 204 var self = this;
201 this.sortStatus.direction); 205 this.prepareSort(self.sortStatus.field, function() {
202 if (sortPermutation) 206 var sortPermutation = self.doSort_(self.sortStatus.field,
203 this.dispatchPermutedEvent_(sortPermutation); 207 self.sortStatus.direction);
208 if (sortPermutation)
209 self.dispatchPermutedEvent_(sortPermutation);
210 });
204 } 211 }
205 }, 212 },
206 213
207 /** 214 /**
208 * Creates sort status with given field and direction. 215 * Creates sort status with given field and direction.
209 * @param {string} field Sort field. 216 * @param {string} field Sort field.
210 * @param {string} direction Sort direction. 217 * @param {string} direction Sort direction.
211 * @return {!Object} Created sort status. 218 * @return {!Object} Created sort status.
212 */ 219 */
213 createSortStatus: function(field, direction) { 220 createSortStatus: function(field, direction) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (a > b) 347 if (a > b)
341 return 1; 348 return 1;
342 return 0; 349 return 0;
343 } 350 }
344 }; 351 };
345 352
346 return { 353 return {
347 ArrayDataModel: ArrayDataModel 354 ArrayDataModel: ArrayDataModel
348 }; 355 };
349 }); 356 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698