mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor: replace var usage with let/const (#7064)
This commit is contained in:
@@ -28,7 +28,7 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
|
||||
// schedule all pending downloads
|
||||
this._enabled = true;
|
||||
var request: DownloadRequest;
|
||||
let request: DownloadRequest;
|
||||
|
||||
while (this._queue.length > 0 && this._currentDownloads < this.maxRequests) {
|
||||
request = this._queue.pop();
|
||||
@@ -56,13 +56,13 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
|
||||
private _addRequest(request: DownloadRequest, onTop: boolean): void {
|
||||
if (request.key in this._pendingDownloads) {
|
||||
var existingRequest = <DownloadRequest>this._pendingDownloads[request.key];
|
||||
const existingRequest = <DownloadRequest>this._pendingDownloads[request.key];
|
||||
this._mergeRequests(existingRequest, request);
|
||||
}
|
||||
else {
|
||||
// TODO: Potential performance bottleneck - traversing the whole queue on each download request.
|
||||
var queueRequest: DownloadRequest;
|
||||
for (var i = 0; i < this._queue.length; i++) {
|
||||
let queueRequest: DownloadRequest;
|
||||
for (let i = 0; i < this._queue.length; i++) {
|
||||
if (this._queue[i].key === request.key) {
|
||||
queueRequest = this._queue[i];
|
||||
break;
|
||||
@@ -83,8 +83,8 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
private _mergeRequests(existingRequest: DownloadRequest, newRequest: DownloadRequest) {
|
||||
if (existingRequest.completed) {
|
||||
if (newRequest.completed) {
|
||||
var existingCompleted = existingRequest.completed;
|
||||
var stackCompleted = function (result: imageSource.ImageSource, key: string) {
|
||||
const existingCompleted = existingRequest.completed;
|
||||
const stackCompleted = function (result: imageSource.ImageSource, key: string) {
|
||||
existingCompleted(result, key);
|
||||
newRequest.completed(result, key);
|
||||
}
|
||||
@@ -97,8 +97,8 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
}
|
||||
if (existingRequest.error) {
|
||||
if (newRequest.error) {
|
||||
var existingError = existingRequest.error;
|
||||
var stackError = function (key: string) {
|
||||
const existingError = existingRequest.error;
|
||||
const stackError = function (key: string) {
|
||||
existingError(key);
|
||||
newRequest.error(key);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
/* tslint:enable:no-unused-variable */
|
||||
|
||||
public _onDownloadCompleted(key: string, image: any) {
|
||||
var request = <DownloadRequest>this._pendingDownloads[key];
|
||||
const request = <DownloadRequest>this._pendingDownloads[key];
|
||||
|
||||
this.set(request.key, image);
|
||||
this._currentDownloads--;
|
||||
@@ -163,7 +163,7 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
}
|
||||
|
||||
public _onDownloadError(key: string, err: Error) {
|
||||
var request = <DownloadRequest>this._pendingDownloads[key];
|
||||
const request = <DownloadRequest>this._pendingDownloads[key];
|
||||
this._currentDownloads--;
|
||||
|
||||
if (request.error) {
|
||||
@@ -215,7 +215,7 @@ export class Cache extends observable.Observable implements definition.Cache {
|
||||
return;
|
||||
}
|
||||
|
||||
var request = this._queue.pop();
|
||||
const request = this._queue.pop();
|
||||
this._download(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as common from "./image-cache-common";
|
||||
import * as trace from "../../trace";
|
||||
|
||||
var LruBitmapCacheClass;
|
||||
let LruBitmapCacheClass;
|
||||
function ensureLruBitmapCacheClass() {
|
||||
if (LruBitmapCacheClass) {
|
||||
return;
|
||||
@@ -16,14 +16,10 @@ function ensureLruBitmapCacheClass() {
|
||||
public sizeOf(key: string, bitmap: android.graphics.Bitmap): number {
|
||||
// The cache size will be measured in kilobytes rather than
|
||||
// number of items.
|
||||
var result = Math.round(bitmap.getByteCount() / 1024);
|
||||
//console.log("sizeOf key: " + result);
|
||||
const result = Math.round(bitmap.getByteCount() / 1024);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//protected entryRemoved(evicted: boolean, key: string, oldValue: android.graphics.Bitmap, newValue: android.graphics.Bitmap): void {
|
||||
// console.log("entryRemoved("+evicted+", "+key+", "+oldValue+", "+newValue+")");
|
||||
//}
|
||||
};
|
||||
|
||||
LruBitmapCacheClass = LruBitmapCache;
|
||||
@@ -37,14 +33,14 @@ export class Cache extends common.Cache {
|
||||
super();
|
||||
|
||||
ensureLruBitmapCacheClass();
|
||||
var maxMemory = java.lang.Runtime.getRuntime().maxMemory() / 1024;
|
||||
var cacheSize = maxMemory / 8;
|
||||
const maxMemory = java.lang.Runtime.getRuntime().maxMemory() / 1024;
|
||||
const cacheSize = maxMemory / 8;
|
||||
this._cache = new LruBitmapCacheClass(cacheSize);
|
||||
|
||||
var that = new WeakRef(this);
|
||||
const that = new WeakRef(this);
|
||||
this._callback = new org.nativescript.widgets.Async.CompleteCallback({
|
||||
onComplete: function (result: any, context: any) {
|
||||
var instance = that.get();
|
||||
const instance = that.get();
|
||||
if (instance) {
|
||||
if (result) {
|
||||
instance._onDownloadCompleted(context, result);
|
||||
@@ -54,7 +50,7 @@ export class Cache extends common.Cache {
|
||||
}
|
||||
},
|
||||
onError: function (err: string, context: any) {
|
||||
var instance = that.get();
|
||||
const instance = that.get();
|
||||
if (instance) {
|
||||
instance._onDownloadError(context, new Error(err));
|
||||
}
|
||||
@@ -67,7 +63,7 @@ export class Cache extends common.Cache {
|
||||
}
|
||||
|
||||
public get(key: string): any {
|
||||
var result = this._cache.get(key);
|
||||
const result = this._cache.get(key);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as common from "./image-cache-common";
|
||||
import * as trace from "../../trace";
|
||||
import * as utils from "../../utils/utils";
|
||||
|
||||
var httpRequest: typeof httpRequestModule;
|
||||
let httpRequest: typeof httpRequestModule;
|
||||
function ensureHttpRequest() {
|
||||
if (!httpRequest) {
|
||||
httpRequest = require("http/http-request");
|
||||
@@ -53,6 +53,7 @@ class MemmoryWarningHandler extends NSObject {
|
||||
|
||||
export class Cache extends common.Cache {
|
||||
private _cache: NSCache<any, any>;
|
||||
|
||||
//@ts-ignore
|
||||
private _memoryWarningHandler: MemmoryWarningHandler;
|
||||
|
||||
@@ -70,7 +71,7 @@ export class Cache extends common.Cache {
|
||||
httpRequest.request({ url: request.url, method: "GET" })
|
||||
.then((response) => {
|
||||
try {
|
||||
var image = UIImage.alloc().initWithData(response.content.raw);
|
||||
const image = UIImage.alloc().initWithData(response.content.raw);
|
||||
this._onDownloadCompleted(request.key, image);
|
||||
} catch (err) {
|
||||
this._onDownloadError(request.key, err);
|
||||
|
||||
Reference in New Issue
Block a user