reafractor(file): add types to promises

This commit is contained in:
Ibrahim Hadeed 2016-09-06 23:33:51 -04:00
parent 2aa998f66f
commit 550b8289c9
No known key found for this signature in database
GPG Key ID: 0431793F665481A4

View File

@ -743,7 +743,7 @@ export class File {
}) })
.then((fe) => { .then((fe) => {
let reader = new FileReader(); let reader = new FileReader();
return new Promise((resolve, reject) => { return new Promise<any>((resolve, reject) => {
reader.onloadend = () => { reader.onloadend = () => {
if (reader.result !== undefined || reader.result !== null) { if (reader.result !== undefined || reader.result !== null) {
resolve(reader.result); resolve(reader.result);
@ -784,7 +784,7 @@ export class File {
}) })
.then((fe) => { .then((fe) => {
let reader = new FileReader(); let reader = new FileReader();
return new Promise((resolve, reject) => { return new Promise<any>((resolve, reject) => {
reader.onloadend = () => { reader.onloadend = () => {
if (reader.result !== undefined || reader.result !== null) { if (reader.result !== undefined || reader.result !== null) {
resolve(reader.result); resolve(reader.result);
@ -826,7 +826,7 @@ export class File {
}) })
.then((fe) => { .then((fe) => {
let reader = new FileReader(); let reader = new FileReader();
return new Promise((resolve, reject) => { return new Promise<any>((resolve, reject) => {
reader.onloadend = () => { reader.onloadend = () => {
if (reader.result !== undefined || reader.result !== null) { if (reader.result !== undefined || reader.result !== null) {
resolve(reader.result); resolve(reader.result);
@ -867,7 +867,7 @@ export class File {
}) })
.then((fe) => { .then((fe) => {
let reader = new FileReader(); let reader = new FileReader();
return new Promise((resolve, reject) => { return new Promise<any>((resolve, reject) => {
reader.onloadend = () => { reader.onloadend = () => {
if (reader.result !== undefined || reader.result !== null) { if (reader.result !== undefined || reader.result !== null) {
resolve(reader.result); resolve(reader.result);
@ -962,7 +962,7 @@ export class File {
* @private * @private
*/ */
private static resolveLocalFilesystemUrl(furl: string): Promise<Entry> { private static resolveLocalFilesystemUrl(furl: string): Promise<Entry> {
return new Promise((resolve, reject) => { return new Promise<Entry>((resolve, reject) => {
try { try {
window.resolveLocalFileSystemURL(furl, (entry) => { window.resolveLocalFileSystemURL(furl, (entry) => {
resolve(entry); resolve(entry);
@ -997,7 +997,7 @@ export class File {
* @private * @private
*/ */
private static getDirectory(fse: DirectoryEntry, dn: string, flags: Flags): Promise<DirectoryEntry> { private static getDirectory(fse: DirectoryEntry, dn: string, flags: Flags): Promise<DirectoryEntry> {
return new Promise((resolve, reject) => { return new Promise<DirectoryEntry>((resolve, reject) => {
try { try {
fse.getDirectory(dn, flags, (de) => { fse.getDirectory(dn, flags, (de) => {
resolve(de); resolve(de);
@ -1016,7 +1016,7 @@ export class File {
* @private * @private
*/ */
private static getFile(fse: DirectoryEntry, fn: string, flags: Flags): Promise<FileEntry> { private static getFile(fse: DirectoryEntry, fn: string, flags: Flags): Promise<FileEntry> {
return new Promise((resolve, reject) => { return new Promise<FileEntry>((resolve, reject) => {
try { try {
fse.getFile(fn, flags, (fe) => { fse.getFile(fn, flags, (fe) => {
resolve(fe); resolve(fe);
@ -1035,7 +1035,7 @@ export class File {
* @private * @private
*/ */
private static remove(fe: Entry): Promise<RemoveResult> { private static remove(fe: Entry): Promise<RemoveResult> {
return new Promise((resolve, reject) => { return new Promise<RemoveResult>((resolve, reject) => {
fe.remove(() => { fe.remove(() => {
resolve({success: true, fileRemoved: fe}); resolve({success: true, fileRemoved: fe});
}, (err) => { }, (err) => {
@ -1049,7 +1049,7 @@ export class File {
* @private * @private
*/ */
private static move(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> { private static move(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
return new Promise((resolve, reject) => { return new Promise<Entry>((resolve, reject) => {
srce.moveTo(destdir, newName, (deste) => { srce.moveTo(destdir, newName, (deste) => {
resolve(deste); resolve(deste);
}, (err) => { }, (err) => {
@ -1063,7 +1063,7 @@ export class File {
* @private * @private
*/ */
private static copy(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> { private static copy(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
return new Promise((resolve, reject) => { return new Promise<Entry>((resolve, reject) => {
srce.copyTo(destdir, newName, (deste) => { srce.copyTo(destdir, newName, (deste) => {
resolve(deste); resolve(deste);
}, (err) => { }, (err) => {
@ -1077,7 +1077,7 @@ export class File {
* @private * @private
*/ */
private static readEntries(dr: DirectoryReader): Promise<Entry[]> { private static readEntries(dr: DirectoryReader): Promise<Entry[]> {
return new Promise((resolve, reject) => { return new Promise<Entry[]>((resolve, reject) => {
dr.readEntries((entries) => { dr.readEntries((entries) => {
resolve(entries); resolve(entries);
}, (err) => { }, (err) => {
@ -1091,7 +1091,7 @@ export class File {
* @private * @private
*/ */
private static rimraf(de: DirectoryEntry): Promise<RemoveResult> { private static rimraf(de: DirectoryEntry): Promise<RemoveResult> {
return new Promise((resolve, reject) => { return new Promise<RemoveResult>((resolve, reject) => {
de.removeRecursively(() => { de.removeRecursively(() => {
resolve({success: true, fileRemoved: de}); resolve({success: true, fileRemoved: de});
}, (err) => { }, (err) => {
@ -1105,7 +1105,7 @@ export class File {
* @private * @private
*/ */
private static createWriter(fe: FileEntry): Promise<FileWriter> { private static createWriter(fe: FileEntry): Promise<FileWriter> {
return new Promise((resolve, reject) => { return new Promise<FileWriter>((resolve, reject) => {
fe.createWriter((writer) => { fe.createWriter((writer) => {
resolve(writer); resolve(writer);
}, (err) => { }, (err) => {
@ -1118,7 +1118,7 @@ export class File {
/** /**
* @private * @private
*/ */
private static write(writer: FileWriter, gu: string | Blob): Promise<void> { private static write(writer: FileWriter, gu: string | Blob): Promise<any> {
if (gu instanceof Blob) { if (gu instanceof Blob) {
return this.writeFileInChunks(writer, gu); return this.writeFileInChunks(writer, gu);
} }
@ -1150,7 +1150,7 @@ export class File {
writer.write(chunk); writer.write(chunk);
} }
return new Promise((resolve, reject) => { return new Promise<any>((resolve, reject) => {
writer.onerror = reject; writer.onerror = reject;
writer.onwrite = () => { writer.onwrite = () => {
if (writtenSize < file.size) { if (writtenSize < file.size) {