webcss / angular-indexedDB

An angularjs serviceprovider to utilize indexedDB with angular
149 stars 99 forks source link

Move all code inside the module definition #41

Open JamesMessinger opened 9 years ago

JamesMessinger commented 9 years ago

I know this project has been taken over by @bramski (https://github.com/bramski/angular-indexedDB), but GitHub won't let me post an issue on that fork, so I'm posting it here instead.

Currently, the following lines are outside of the angular.module definition, which means they run immediately when the file is loaded, rather than waiting for angular.bootstrap to occur.

var IDBKeyRange, indexedDB,
  __slice = [].slice;

indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

IDBKeyRange = window.IDBKeyRange || window.mozIDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;

The problem is that if I'm running in a browser that doesn't natively support IndexedDB, and I'm loading a polyfill instead, then the above code will only work if the polyfill is loaded before the angular-indexed-db.js file. But if the polyfill is being loaded dynamically (say, as an Angular module, a Require.js module, a Browserify package, or a Cordova plugin), then the polyfill won't load in time, and Angular-IndexedDB won't work.

To fix this problem, the four lines of code shown above just need to be moved inside of the angular.module definition. That way, they won't run until all dynamically-loaded scripts are finished loading and angular.bootstrap is called.

bramski commented 9 years ago

Ahh yes. I had neglected to turn on issues in the other fork @BigstickCarpet. You should be able to make this issue over there now. Let me know if you cannot. I am happy to fix this issue, or you yourself may issue a pull request if you feel like contributing. Looks like a pretty simple fix. Cheers.