bramski/angular-indexedDB

IE11 DataError on eachBy with no options

jrzerr opened this issue · 3 comments

I got a DataError (code 0) on IE11 Edge when using the eachBy on an index but I did not pass any options. I am calling eachBy without the second parameter, like eachBy("indexName"). The problem is that when the query keyRange is set using:

                    ObjectStore.prototype.eachBy = function(indexName, options) {
                        ...
                        q = new Query();
                        ...
                        q.keyRange = keyRangeForOptions(options);
                        ...
                    };

The keyRangeForOptions function does not return anything in the case when options is not specified. This does not appear to affect Chrome or Firefox as I've been using the code for a while. However, I found that IE11 will not work with an undefined keyRange, it must be set to null. So my fix was to change:

                keyRangeForOptions = function(options) {
                    if (options.beginKey && options.endKey) {
                        return IDBKeyRange.bound(options.beginKey, options.endKey);
                    }
                };

to:

                keyRangeForOptions = function(options) {
                    if (options.beginKey && options.endKey) {
                        return IDBKeyRange.bound(options.beginKey, options.endKey);
                    } else {
                        return null;
                    }
                };

I will work on a Pull Request when I get time. I just wanted to make sure I documented it here so have a record of what the fix was.

👍

I'll add a milestone to the project for IE11 support. There's another issue in that realm.

I found this one after I used #34 to fix my first IE11 error. Thanks!