forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage-cache.d.ts
More file actions
110 lines (101 loc) · 3.57 KB
/
image-cache.d.ts
File metadata and controls
110 lines (101 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Contains the Cache class, which handles image download requests and caches the already downloaded images.
*/
declare module "ui/image-cache" {
import observable = require("data/observable");
import imageSource = require("image-source");
/**
* Represents a single download request.
*/
export interface DownloadRequest {
/**
* The url of the image.
*/
url: string;
/**
* The key used to cache the image.
*/
key: string;
/**
* An optional function to be called when the download is complete.
*/
completed?: (image: any, key: string) => void;
}
/**
* Represents a class that stores handles image download requests and caches the already downloaded images.
*/
export class Cache extends observable.Observable {
/**
* String value used when hooking to downloaded event.
*/
public static downloadedEvent: string;
/**
* The image to be used to notify for a pending download request - e.g. loading indicator.
*/
placeholder: imageSource.ImageSource;
/**
* The maximum number of simultaneous download requests. Defaults to 5.
*/
maxRequests: number;
/**
* Enables previously suspended download requests.
*/
enableDownload(): void;
/**
* Temporary disables download requests.
*/
disableDownload(): void;
/**
* Adds a new download request at the top of the download queue. This will be the next immediate download to start.
*/
push(request: DownloadRequest);
/**
* Adds a new download request at the end of the download queue. This will be the last download to start.
*/
enqueue(request: DownloadRequest);
/**
* Gets the image for the specified key. May be undefined if the key is not present in the cache.
*/
get(key: string): any;
/**
* Sets the image for the specified key.
*/
set(key: string, image: any): void;
/**
* Removes the cache for the specified key.
*/
remove(key: string): void;
/**
* Removes all the previously cached images.
*/
clear(): void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (args: observable.EventData) => void , thisArg?: any);
/**
* Raised when the image has been downloaded.
*/
on(event: "downloaded", callback: (args: DownloadedData) => void , thisArg?: any);
//@private
_downloadCore(request: DownloadRequest);
_onDownloadCompleted(key: string, image: any);
//@endprivate
}
/**
* Provides data for downloaded event.
*/
export interface DownloadedData extends observable.EventData {
/**
* A string indentifier of the cached image.
*/
key: string;
/**
* Gets the cached image.
*/
image: imageSource.ImageSource;
}
}