Skip to content

Commit

Permalink
fix(provider): remove platform.ready (#96)
Browse files Browse the repository at this point in the history
* remove the platform.ready for the Observable, faster loading and better behavior in bad network area

* remove the platform.ready for the Observable, faster loading and better behavior in bad network area
  • Loading branch information
Thibaut authored and ihadeed committed Sep 7, 2017
1 parent 4ea0375 commit 6c3b20e
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,23 @@ export class ImageLoader {
private fileTransfer: FileTransfer,
private platform: Platform
) {
platform.ready().then(() => {
if (!platform.is('cordova')) {
// we are running on a browser, or using livereload
// plugin will not function in this case
this.isInit = true;
this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.');
} else {
Observable.fromEvent(document, 'deviceready').first().subscribe(res => {
if (this.nativeAvailable) {
this.initCache();
} else {
// we are running on a browser, or using livereload
// plugin will not function in this case
this.isInit = true;
this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.');
}
})
}
});
if (!platform.is('cordova')) {
// we are running on a browser, or using livereload
// plugin will not function in this case
this.isInit = true;
this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.');
} else {
Observable.fromEvent(document, 'deviceready').first().subscribe(res => {
if (this.nativeAvailable) {
this.initCache();
} else {
// we are running on a browser, or using livereload
// plugin will not function in this case
this.isInit = true;
this.throwWarning('You are running on a browser or using livereload, IonicImageLoader will not function, falling back to browser loading.');
}
});
}
}

/**
Expand Down Expand Up @@ -357,7 +355,7 @@ export class ImageLoader {
.then(files => Promise.all(files.map(this.addFileToIndex.bind(this))))
.then(() => {
// Sort items by date. Most recent to oldest.
this.cacheIndex = this.cacheIndex.sort((a: IndexItem, b: IndexItem): number => a>b?-1:a<b?1:0);
this.cacheIndex = this.cacheIndex.sort((a: IndexItem, b: IndexItem): number => a > b ? -1 : a < b ? 1 : 0);
this.indexed = true;
return Promise.resolve();
})
Expand Down

0 comments on commit 6c3b20e

Please sign in to comment.