superfeedr / indexeddb-backbonejs-adapter

An indexedDB adapter for Backbonejs
http://blog.superfeedr.com/indexeddb-backbonejs-adapter/
MIT License
248 stars 61 forks source link

Error thrown while aborting fetch #80

Open ncortines opened 9 years ago

ncortines commented 9 years ago

Hi,

I found that triggering abort on a fetch operation with a range condition works fine:

movies.fetch({
    conditions: {
        title: ['A', 'Z']
    }
}).abort()

However when specifying a single value condition error is thrown upon abort invocation:

movies.fetch({
    conditions: {
        title: 'Goonies'
    }
}).abort()

throws Uncaught DataError: Failed to execute 'continue' on 'IDBCursor': The parameter is less than or equal to this cursor's position.

The problem since to lay in this piece of code, which seems to asume the first case scenario:

if (bounds && options.conditions[index.keyPath]) {
    cursor.continue(options.conditions[index.keyPath][1] + 1); /* We need to 'terminate' the cursor cleany, by moving to the end */

The following seems to fix the problem:

if (bounds && options.conditions[index.keyPath] && _.isArray(options.conditions[index.keyPath])) {
    cursor.continue(options.conditions[index.keyPath][1] + 1); /* We need to 'terminate' the cursor cleany, by moving to the end */

Please let me know what do you think.

Thanks!