OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 import 'dart:sky' as sky; | |
6 import 'dart:collection'; | |
7 | |
8 class ImageCache { | |
abarth-chromium
2015/06/02 00:52:47
There's no need for this class. You can just put
jackson
2015/06/02 01:18:25
Acknowledged.
| |
9 static final ImageCache _sharedCache = new ImageCache(); | |
10 static ImageCache shared() { return _sharedCache; } | |
11 | |
12 final HashMap pendingRequests = new HashMap<String, List<sky.ImageLoaderCallba ck>>(); | |
13 final HashMap completedRequests = new HashMap<String, sky.Image>(); | |
abarth-chromium
2015/06/02 00:52:47
It's more important to put the types on the declar
jackson
2015/06/02 01:18:25
Acknowledged.
| |
14 | |
15 void load(String url, sky.ImageLoaderCallback callback) { | |
16 if (completedRequests.containsKey(url)) { | |
17 callback(completedRequests[url]); | |
18 } else if (pendingRequests.containsKey(url)) { | |
abarth-chromium
2015/06/02 00:52:47
Using putIfAbsent [1] is the idiomatic (and faster
jackson
2015/06/02 01:18:25
Acknowledged.
| |
19 pendingRequests[url].add(callback); | |
20 } else { | |
21 pendingRequests[url] = new List(); | |
22 pendingRequests[url].add(callback); | |
23 new sky.ImageLoader(url, (image) { | |
24 completedRequests[url] = image; | |
25 pendingRequests[url].forEach((c) => c(image)); | |
26 pendingRequests[url].remove(url); | |
27 }).load(); | |
28 } | |
29 } | |
30 } | |
OLD | NEW |