es2015/object-store/AbstractReadOnlyStorage.js
function list(storage, keyRange, filter, direction, unique, pageSize,
    storageFactory) {
  return new Promise((resolve, reject) => {
    let items = []

    storage.createCursorFactory(keyRange, direction)((cursor) => {
      if (!filter || filter(cursor.record, cursor.primaryKey, cursor.key)) {
        if (items.length === pageSize) {
          finalize(true, cursor.key, cursor.primaryKey)
          return
        } else {
          items.push(cursor.record)
        }
      }
      
      cursor.continue()
    }).then(() => finalize(false, null, null)).catch(error => reject(error))

    function finalize(hasNextPage, nextKey, nextPrimaryKey) {
      resolve(new RecordList(items, storageFactory, nextKey, nextPrimaryKey,
          direction, unique, filter, pageSize, hasNextPage))
    }
  })
}
function list(storage, keyRange, filter, direction, unique, pageSize,
    storageFactory) {
  return new Promise((resolve, reject) => {
    let items = []

    storage.createCursorFactory(keyRange, direction)((cursor) => {
      if (!filter || filter(cursor.record, cursor.primaryKey, cursor.key)) {
        if (items.length === pageSize) {
          finalize(true, cursor.key, cursor.primaryKey)
          return
        } else {
          items.push(cursor.record)
        }
      }
      
      cursor.continue()
    }).then(() => finalize(false, null, null)).catch(error => reject(error))

    function finalize(hasNextPage, nextKey, nextPrimaryKey) {
      resolve(new RecordList(items, storageFactory, nextKey, nextPrimaryKey,
          direction, unique, filter, pageSize, hasNextPage))
    }
  })
}
Creates a promise that resolves to a record list containing the first page
of records matching the provided filter.

@param {AbstractReadOnlyStorage} storage The current storage accessor - will
be used to fetch the first page of records.
@param {(undefined|IDBKeyRange)} keyRange The key range to use for the first
page or records.
@param {(undefined|function(*, (number|string|Date|Array), (number|string|Date|Array)): boolean)} filter
The filter function restricting the records that will be listed.
If a function is provided, the first argument will be set to the
record, the second argument will be set to the primary key of the
record, and the third argument will be set to the key referencing the
record (the primary key if traversing an object store).
@param {CursorDirection} direction The direction in which the records in the
storage should be listed.
@param {boolean} unique When {@code true}, the keys by which the records are
organized in the store are always unique for each record.
@param {number} pageSize The maximum number of records per page. Must be a
positive integer.
@param {function(): AbstractReadOnlyStorage} storageFactory A function that
creates a new read-only transaction and returns this storage accessor
each time it is invoked.
@return {Promise<RecordList<*>>} A promise that resolves to a record list of
the fetched records matching the filter.