Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise-plugin: denodeify not working correctly #45

Open
cgrossde opened this issue Feb 26, 2016 · 0 comments
Open

Promise-plugin: denodeify not working correctly #45

cgrossde opened this issue Feb 26, 2016 · 0 comments

Comments

@cgrossde
Copy link

Denodeification does not work correctly for me and when calling get() on a store I get an exception:
TypeError: undefined is not a function at IDBRequest.onsuccess .... This is not the only method that fails when trying to use it as a promise.
Sample code:

import treo from 'treo'
import treoPromise from 'treo/plugins/treo-promise'

// Init DB
    const schema = treo.schema()
      .version(1)
        .addStore('apps', { key: 'aid' })
        .addStore('notifications', { key: 'id' })
        .addIndex('byAppId', 'aid')
        .addIndex('byDate', 'date')

    const db = treo('pushover', schema)
      .use(treoPromise())

    this.appDB = db.store('apps')
    this.notificationDB = db.store('notifications')

function isNew(notification) {
  return this.notificationDB.get(notification.id)
      .then(function(result) {
        if (result !== undefined) {
          throw new Error('notificationExists')
        }
      })
}

I could track down the problem in the promise-plugin:

// Method name and argument count
var storeMethods = [
  ['put', 3],
  ['get', 2],
  ['del', 2],
  ['count', 1],
  ['clear', 1],
  ['batch', 2],
  ['all', 1],
];
// Later in the patch method
// Denodeification with argument count specified in the storeMethods array
object[m[0]] = denodeify(object[m[0]], m[1]);
// ...

The argument count in the array is wrong. For get it works if I use an argument count of 1. But why do you bother maintaining a list with argument counts? You could just omit the count and the denodeify() method would figure it out itself (https://github.com/then/promise/blob/0a8c481dd8e9825ffd05251658f22d64bead1315/src/node-extensions.js#L13).
This solves the problem:

object[m[0]] = denodeify(object[m[0]]);

Was there a reason for manually specifying the count? Do you think I maybe ran into this problem because of something webpack does?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant