Skip to content

Move all code inside the module definition #41

@JamesMessinger

Description

@JamesMessinger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions