OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
9 | 9 |
10 import 'package:async/async.dart' hide StreamQueue; | 10 import 'package:async/async.dart' hide StreamQueue; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 helper(element); | 185 helper(element); |
186 } else { | 186 } else { |
187 result.add(element); | 187 result.add(element); |
188 } | 188 } |
189 } | 189 } |
190 } | 190 } |
191 helper(nested); | 191 helper(nested); |
192 return result; | 192 return result; |
193 } | 193 } |
194 | 194 |
195 /// Creates a new map from [map] with new keys and values. | |
196 /// | |
197 /// The return values of [keyFn] are used as the keys and the return values of | |
198 /// [valueFn] are used as the values for the new map. | |
199 Map/*<K2, V2>*/ mapMap/*<K1, V1, K2, V2>*/(Map/*<K1, V1>*/ map, | |
200 {/*=K2*/ key(/*=K1*/ key, /*=V1*/ value), | |
201 /*=V2*/ value(/*=K1*/ key, /*=V1*/ value)}) { | |
202 key ??= (key, _) => key as dynamic/*=K2*/; | |
203 value ??= (_, value) => value as dynamic/*=V2*/; | |
204 | |
205 return new Map.fromIterable(map.keys, | |
206 key: (mapKey) => key(mapKey as dynamic/*=K1*/, map[mapKey]), | |
207 value: (mapKey) => value(mapKey as dynamic/*=K1*/, map[mapKey])); | |
208 } | |
209 | |
210 /// Returns a new map with all values in both [map1] and [map2]. | |
211 /// | |
212 /// If there are conflicting keys, [value] is used to merge them. If it's | |
213 /// not passed, [map2]'s value wins. | |
214 Map/*<K, V>*/ mergeMaps/*<K, V>*/(Map/*<K, V>*/ map1, Map/*<K, V>*/ map2, | |
215 {/*=V*/ value(/*=V*/ value1, /*=V*/ value2)}) { | |
216 var result = new Map/*<K, V>*/.from(map1); | |
217 map2.forEach((key, mapValue) { | |
218 if (value == null || !result.containsKey(key)) { | |
219 result[key] = mapValue; | |
220 } else { | |
221 result[key] = value(result[key], mapValue); | |
222 } | |
223 }); | |
224 return result; | |
225 } | |
226 | |
227 /// Like [runZoned], but [zoneValues] are set for the callbacks in | 195 /// Like [runZoned], but [zoneValues] are set for the callbacks in |
228 /// [zoneSpecification] and [onError]. | 196 /// [zoneSpecification] and [onError]. |
229 runZonedWithValues(body(), {Map zoneValues, | 197 runZonedWithValues(body(), {Map zoneValues, |
230 ZoneSpecification zoneSpecification, Function onError}) { | 198 ZoneSpecification zoneSpecification, Function onError}) { |
231 return runZoned(() { | 199 return runZoned(() { |
232 return runZoned(body, | 200 return runZoned(body, |
233 zoneSpecification: zoneSpecification, onError: onError); | 201 zoneSpecification: zoneSpecification, onError: onError); |
234 }, zoneValues: zoneValues); | 202 }, zoneValues: zoneValues); |
235 } | 203 } |
236 | 204 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 return BASE64.encode(data); | 357 return BASE64.encode(data); |
390 } | 358 } |
391 | 359 |
392 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 360 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
393 shelf.Middleware nestingMiddleware(String beneath) { | 361 shelf.Middleware nestingMiddleware(String beneath) { |
394 return (handler) { | 362 return (handler) { |
395 var pathHandler = new PathHandler()..add(beneath, handler); | 363 var pathHandler = new PathHandler()..add(beneath, handler); |
396 return pathHandler.handler; | 364 return pathHandler.handler; |
397 }; | 365 }; |
398 } | 366 } |
OLD | NEW |