Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit 30cb4c5

Browse files
committed
only get defaults when we need it
1 parent 9817cc2 commit 30cb4c5

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ module.exports = function (archive, opts) {
88

99
var db = toiletdb({name: '/dat.json', fs: archive})
1010
var fileDb = opts.file ? toiletdb(opts.file) : null
11-
var defaults = {
12-
title: '',
13-
description: '',
14-
url: 'dat://' + stringKey(archive.key)
15-
}
1611

1712
var that = {
1813
read: function (cb) {
@@ -39,13 +34,21 @@ module.exports = function (archive, opts) {
3934
create: function (data, cb) {
4035
if (typeof data === 'function') return that.create(null, data)
4136
if (!archive.writable) return cb(new Error('Archive not writable'))
42-
data = xtend(defaults, data)
37+
data = xtend(getdefaults(), data)
4338
that.write(data, cb)
4439
}
4540
}
4641

4742
return that
4843

44+
function getdefaults () {
45+
return {
46+
title: '',
47+
description: '',
48+
url: 'dat://' + stringKey(archive.key)
49+
}
50+
}
51+
4952
function writeAll (data, cb) {
5053
if (!archive.writable) return cb(new Error('Archive not writable'))
5154
var keys = Object.keys(data)

0 commit comments

Comments
 (0)