log.js
function each (opts, callback) {
    if (!callback) {
      callback = opts
      opts = { order: 'created' }
    }

    var store = this.store
    return new Promise(function (resolve) {
      function nextPage (get) {
        get().then(function (page) {
          var result
          for (var i = page.entries.length - 1; i >= 0; i--) {
            var entry = page.entries[i]
            result = callback(entry[0], entry[1])
            if (result === false) break
          }

          if (result === false || !page.next) {
            resolve()
          } else {
            nextPage(page.next)
          }
        })
      }

      nextPage(store.get.bind(store, opts))
    })
  }
function each (opts, callback) {
    if (!callback) {
      callback = opts
      opts = { order: 'created' }
    }

    var store = this.store
    return new Promise(function (resolve) {
      function nextPage (get) {
        get().then(function (page) {
          var result
          for (var i = page.entries.length - 1; i >= 0; i--) {
            var entry = page.entries[i]
            result = callback(entry[0], entry[1])
            if (result === false) break
          }

          if (result === false || !page.next) {
            resolve()
          } else {
            nextPage(page.next)
          }
        })
      }

      nextPage(store.get.bind(store, opts))
    })
  }
function each ( opts , callback ) { if ( ! callback ) { callback = opts opts = { order : 'created' } } var store = this . store return new Promise ( function ( resolve ) { function nextPage ( get ) { get ( ) . then ( function ( page ) { var result for ( var i = page . entries . length - 1 ; i >= 0 ; i -- ) { var entry = page . entries [ i ] result = callback ( entry [ 0 ] , entry [ 1 ] ) if ( result === false ) break } if ( result === false || ! page . next ) { resolve ( ) } else { nextPage ( page . next ) } } ) } nextPage ( store . get . bind ( store , opts ) ) } ) }
Iterates through all actions, from last to first.

Return false from callback if you want to stop iteration.

@param {object} [opts] Iterator options.
@param {'added'|'created'} [opts.order='created'] Sort entries by created
time or when they was
added to this log.
@param {iterator} callback Function will be executed on every action.

@return {Promise} When iteration will be finished
by iterator or end of actions.

@example
log.each((action, meta) => {
if (compareTime(meta.id, lastBeep) <= 0) {
return false;
} else if (action.type === 'beep') {
beep()
lastBeep = meta.id
return false;
}
})
Iterates through all actions from last to first .