Skip to content

Simplify PouchDB ctor definitions #23

@AGBrown

Description

@AGBrown

Relates to #22

Consider:

    /** The api module for the pouchdb callback pattern */
    module callback {
        /** The main pouchDB interface (callback pattern) */
        interface PouchDB extends api.db.Callback { }
    }
    /** The api module for the pouchdb promise pattern */
    module promise {
        /** The main pouchDB interface (promise pattern) */
        interface PouchDB extends api.db.Promisable { }
    }
    /** The api module for the pouchdb promise pattern (constructor only) */
    module thenable {
        /**
         * Special case class returned by the constructors of the promise api pouchDB.
         * Usually only a `pouchdb.promise.PouchDB` reference would be kept, assigned by
         * the `then` of the constructor.
         */
        interface PouchDB extends promise.PouchDB, async.Thenable<promise.PouchDB> { }
    }
  1. thenable.PouchDB is a bad name (a real thenable does not have a catch anyway)
  2. thenable.PouchDB is just there to be the return type for the promise-based constructors (i.e. to prevent then showing up on your pouchdb db variable)
  3. promise.PouchDB is exactly an api.db.Promisable
  4. but pouchdb.promise.PouchDB is there because, ideally, you would be able to do var db : pouchdb.PouchDB. However we are splitting callable and promise interfaces to help end-users, so var db : pouchdb.promise.PouchDB is seemed marginally more explanatory (and has one less level of nesting) than var db : pouchdb.api.db.Promisable

@fredgalvao commented, rightly, that this structure is confusing. So ... how can we improve it?

Suggestions:

  1. Rename module promise to module promisable in keeping with Rename Promise interfaces #22.
  2. or rename module thenable to module promisable and remove module promise.
  3. Or just move the interfaces out of module db and use those instead of module callback and module promise

I personally don't like this (which would be a vote against option 2):

    var dbp: pouchdb.api.db.Promisable;
     new PouchDB("name")
     .then(db => dbp = db);

compared to

    var dbp: pouchdb.promise.PouchDB;
     new PouchDB("name")
     .then(db => dbp = db);

Purely because dbp is a PouchDB, not a Promisable

Option 3 might be the best option. module db is a little superfluous - I only put it there to be clear where the main db interfaces were defined, but then ended up needing the callback and promise modules which are only there to improve the external naming.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions