aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-12 11:34:44 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-06-12 11:34:44 -1000
commit0d1706f6788075c581198d8ef130c5035aa7eab2 (patch)
treef7b9331a698f0cfc49803545a29475f6eb113ffa
parent9744455da720324fcef0a9c6c55b94df0e62ec41 (diff)
downloadpatchfoo-0d1706f6788075c581198d8ef130c5035aa7eab2.tar.gz
patchfoo-0d1706f6788075c581198d8ef130c5035aa7eab2.zip
Move mergeOpts into util
-rw-r--r--lib/serve.js24
-rw-r--r--lib/util.js12
2 files changed, 18 insertions, 18 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 3ade4f6..354e75f 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -594,8 +594,8 @@ Serve.prototype.syncPager = function (opts) {
var max = (reverse ? opts.first : opts.last) || Number(q.lt)
var minDate = new Date(min)
var maxDate = new Date(max)
- var qOlder = mergeOpts(q, {lt: min, gt: undefined, forwards: undefined})
- var qNewer = mergeOpts(q, {gt: max, lt: undefined, forwards: 1})
+ var qOlder = u.mergeOpts(q, {lt: min, gt: undefined, forwards: undefined})
+ var qNewer = u.mergeOpts(q, {gt: max, lt: undefined, forwards: 1})
var atNewest = reverse ? !q.lt : !max
var atOldest = reverse ? !min : !q.gt
if (atNewest && !reverse) qOlder.lt++
@@ -1125,31 +1125,19 @@ Serve.prototype.renderThread = function () {
)
}
-function mergeOpts(a, b) {
- var obj = {}, k
- for (k in a) {
- obj[k] = a[k]
- }
- for (k in b) {
- if (b[k] != null) obj[k] = b[k]
- else delete obj[k]
- }
- return obj
-}
-
Serve.prototype.renderThreadPaginated = function (opts, feedId, q) {
var self = this
function linkA(opts, name) {
- var q1 = mergeOpts(q, opts)
+ var q1 = u.mergeOpts(q, opts)
return h('a', {href: '?' + qs.stringify(q1)}, name || q1.limit)
}
function links(opts) {
var limit = opts.limit || q.limit || 10
return h('tr', h('td.paginate', {colspan: 3},
opts.forwards ? '↑ newer ' : '↓ older ',
- linkA(mergeOpts(opts, {limit: 1})), ' ',
- linkA(mergeOpts(opts, {limit: 10})), ' ',
- linkA(mergeOpts(opts, {limit: 100}))
+ linkA(u.mergeOpts(opts, {limit: 1})), ' ',
+ linkA(u.mergeOpts(opts, {limit: 10})), ' ',
+ linkA(u.mergeOpts(opts, {limit: 100}))
))
}
diff --git a/lib/util.js b/lib/util.js
index e4cf415..57183d2 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -186,3 +186,15 @@ u.pullSlice = function (start, end) {
}
}
}
+
+u.mergeOpts = function (a, b) {
+ var obj = {}, k
+ for (k in a) {
+ obj[k] = a[k]
+ }
+ for (k in b) {
+ if (b[k] != null) obj[k] = b[k]
+ else delete obj[k]
+ }
+ return obj
+}