本文整理汇总了TypeScript中localforage.localforage类的典型用法代码示例。如果您正苦于以下问题:TypeScript localforage类的具体用法?TypeScript localforage怎么用?TypeScript localforage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了localforage类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getZbook
async function getZbook(book : Book) : Promise<Database> {
let file = files[book.file];
if (!file) {
file = await localforage.getItem<BookFile>(book.file);
if (file) {
if (file.version !== book.file_version) {
// Update book in background.
fetchBinary(
book.url,
"Updating book " + book.name + "..."
).then(data => {
file.data = data;
// TODO: notify UI book has been updated
files[book.file] = file;
return localforage.setItem(book.file, file);
});
}
}
else {
file = {
version: book.file_version,
data: await fetchBinary(
book.url,
"Downloading book " + book.name + "..."
)
};
await localforage.setItem(book.file, file);
}
}
return new Database(inflate(file.data));
}
示例2: getCatalog
async function getCatalog() {
let language = await getLanguage();
let catalog = await localforage.getItem<Folder>("catalog");
if (catalog &&
platform == await localforage.getItem("platform") &&
language == await localforage.getItem("language")) {
updateCatalog(language); // check for update in background
return catalog; // But return cached value immediately
}
return await updateCatalog(language);
}
示例3: updateCatalog
async function updateCatalog(language) : Promise<Folder> {
let update = await fetchJson(
"http://tech.lds.org/glweb?action=catalog.query.modified&languageid=" +
language + "&platformid=" + platform + "&format=json",
"Checking for catalog updates..."
);
let version = update.version;
if (version == await localforage.getItem("version")) {
console.log("No catalog updates.");
return;
}
let result = await fetchJson(
"http://tech.lds.org/glweb?action=catalog.query&languageid=" +
language + "&platformid=" + platform + "&format=json",
"Downloading catalog..."
);
await localforage.setItem("catalog", result.catalog);
await localforage.setItem("version", version);
await localforage.setItem("language", language);
await localforage.setItem("platform", platform);
// TODO: use book.versions API to update any downloaded books.
return result.catalog;
}
示例4:
).then(data => {
file.data = data;
// TODO: notify UI book has been updated
files[book.file] = file;
return localforage.setItem(book.file, file);
});