toArray: function()

in public/dexie.js [4170:4214]


        toArray: function (cb) {
          var ctx = this._ctx;
          return this._read(function (resolve, reject, idbstore) {
            if (
              hasGetAll &&
              ctx.dir === "next" &&
              isPlainKeyRange(ctx, true) &&
              ctx.limit > 0
            ) {
              // Special optimation if we could use IDBObjectStore.getAll() or
              // IDBKeyRange.getAll():
              var readingHook = ctx.table.hook.reading.fire;
              var idxOrStore = getIndexOrStore(ctx, idbstore);
              var req =
                ctx.limit < Infinity
                  ? idxOrStore.getAll(ctx.range, ctx.limit)
                  : idxOrStore.getAll(ctx.range);
              req.onerror = eventRejectHandler(reject);
              req.onsuccess =
                readingHook === mirror
                  ? eventSuccessHandler(resolve)
                  : eventSuccessHandler(function (res) {
                      try {
                        resolve(res.map(readingHook));
                      } catch (e) {
                        reject(e);
                      }
                    });
            } else {
              // Getting array through a cursor.
              var a = [];
              iter(
                ctx,
                function (item) {
                  a.push(item);
                },
                function arrayComplete() {
                  resolve(a);
                },
                reject,
                idbstore
              );
            }
          }, cb);
        },