Skip to content

Commit

Permalink
Allow messages.read() opts to take priority over defaults
Browse files Browse the repository at this point in the history
Changed the order of the `xtend()` assignment, so that passed opts
 takes priority making it possible to override the
`{reverse: true}`  with a `false` value instead.

Also added some semi-accurate documentation to that method based on
assumptions.
  • Loading branch information
Tony Ivanov committed Nov 18, 2018
1 parent 12bafdd commit 2b30dcd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions views/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ module.exports = function (lvl) {
},

api: {
/**
* Creates a read stream of messages
* @param {Object} core - HyperCore to stream messages from.
* @param {String} channel - Name of channel
* @param {Object} opts :
* `gt` {Number} - Filter by timestamp where message.timestamp is greater than `gt`
* `lt` {Number} - Filter by timestamp where message.timestamp is lesser than `lt`
* Supports all levelup.createValueStream() options as well:
* `reverse` {Boolean} - Streams messages in Ascending time order, default: `true` (Descending)
*/
read: function (core, channel, opts) {
opts = opts || {}

Expand All @@ -52,9 +62,7 @@ module.exports = function (lvl) {
else opts.lt = 'msg!' + channel + '~'

this.ready(function () {
var v = lvl.createValueStream(xtend(opts, {
reverse: true
}))
var v = lvl.createValueStream(xtend({reverse: true}, opts))
v.pipe(t)
})

Expand Down

0 comments on commit 2b30dcd

Please sign in to comment.