| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var createClassWrapper = requireNative('utils').createClassWrapper; | 5 var createClassWrapper = requireNative('utils').createClassWrapper; |
| 6 var nativeDeepCopy = requireNative('utils').deepCopy; | 6 var nativeDeepCopy = requireNative('utils').deepCopy; |
| 7 var schemaRegistry = requireNative('schema_registry'); | 7 var schemaRegistry = requireNative('schema_registry'); |
| 8 var CHECK = requireNative('logging').CHECK; | 8 var CHECK = requireNative('logging').CHECK; |
| 9 var DCHECK = requireNative('logging').DCHECK; | 9 var DCHECK = requireNative('logging').DCHECK; |
| 10 var WARNING = requireNative('logging').WARNING; | 10 var WARNING = requireNative('logging').WARNING; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 /** | 26 /** |
| 27 * Assuming |array_of_dictionaries| is structured like this: | 27 * Assuming |array_of_dictionaries| is structured like this: |
| 28 * [{id: 1, ... }, {id: 2, ...}, ...], you can use | 28 * [{id: 1, ... }, {id: 2, ...}, ...], you can use |
| 29 * lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2. | 29 * lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2. |
| 30 * @param {Array<Object<?>>} array_of_dictionaries | 30 * @param {Array<Object<?>>} array_of_dictionaries |
| 31 * @param {string} field | 31 * @param {string} field |
| 32 * @param {?} value | 32 * @param {?} value |
| 33 */ | 33 */ |
| 34 function lookup(array_of_dictionaries, field, value) { | 34 function lookup(array_of_dictionaries, field, value) { |
| 35 var filter = function (dict) {return dict[field] == value;}; | 35 var filter = function (dict) {return dict[field] == value;}; |
| 36 var matches = array_of_dictionaries.filter(filter); | 36 var matches = $Array.filter(array_of_dictionaries, filter); |
| 37 if (matches.length == 0) { | 37 if (matches.length == 0) { |
| 38 return undefined; | 38 return undefined; |
| 39 } else if (matches.length == 1) { | 39 } else if (matches.length == 1) { |
| 40 return matches[0] | 40 return matches[0] |
| 41 } else { | 41 } else { |
| 42 throw new Error("Failed lookup of field '" + field + "' with value '" + | 42 throw new Error("Failed lookup of field '" + field + "' with value '" + |
| 43 value + "'"); | 43 value + "'"); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 $Function.apply(func, null, args); | 165 $Function.apply(func, null, args); |
| 166 }); | 166 }); |
| 167 } | 167 } |
| 168 | 168 |
| 169 exports.$set('forEach', forEach); | 169 exports.$set('forEach', forEach); |
| 170 exports.$set('loadTypeSchema', loadTypeSchema); | 170 exports.$set('loadTypeSchema', loadTypeSchema); |
| 171 exports.$set('lookup', lookup); | 171 exports.$set('lookup', lookup); |
| 172 exports.$set('expose', expose); | 172 exports.$set('expose', expose); |
| 173 exports.$set('deepCopy', deepCopy); | 173 exports.$set('deepCopy', deepCopy); |
| 174 exports.$set('promise', promise); | 174 exports.$set('promise', promise); |
| OLD | NEW |