Rewrote image-cache to use the native image caching features, i.e. LruCache and NSCache.

This commit is contained in:
Rossen Hristov
2015-04-15 16:27:27 +03:00
parent 9e9c25dff7
commit 3d0882ffa7
6 changed files with 101 additions and 51 deletions

View File

@@ -50,7 +50,11 @@ export class RedditViewModel extends observable.Observable {
} else if (redditAppViewModel.cache) {
var url = this._source.thumbnail;
var imgSource = redditAppViewModel.cache.get(url);
var imgSource: imageSource.ImageSource;
var image = redditAppViewModel.cache.get(url);
if (image) {
imgSource = imageSource.fromNativeSource(image);
}
if (imgSource) {
this._thumbnailImageSource = imgSource;
@@ -61,11 +65,12 @@ export class RedditViewModel extends observable.Observable {
redditAppViewModel.cache.push({
key: url,
url: url,
completed: (result: imageSource.ImageSource, key: string) => {
completed: (image: any, key: string) => {
if (url === key) {
this.isLoading = false;
this._thumbnailImageSource = result;
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: result });
var imgSource = imageSource.fromNativeSource(image);
this._thumbnailImageSource = imgSource;
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: imgSource });
}
}
});