Skip to content

Commit

Permalink
feat(constructor): create custom Store with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Jul 28, 2015
1 parent df25786 commit 3453aaf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ PouchDB.plugin({
unsyncedLocalDocs: UnsyncedLocalDocs.unsyncedLocalDocs
})

module.exports = Store

function Store (dbName, options) {
if (!(this instanceof Store)) return new Store(dbName, options)
if (typeof dbName !== 'string') throw new Error('Must be a valid string.')
Expand All @@ -39,6 +37,19 @@ function Store (dbName, options) {
return api
}

Store.defaults = function (defaultOpts) {
function StoreAlt (dbName, options) {
if (typeof dbName !== 'string') throw new Error('Must be a valid string.')
options = options || {}

options = merge(defaultOpts, options)

return Store(dbName, options)
}

return StoreAlt
}

function mapUnsyncedLocalIds (options) {
return this.unsyncedLocalDocs.call(this, options)

Expand Down Expand Up @@ -99,3 +110,5 @@ function subscribeToInternalEvents (emitter) {
localStorageWrapper.removeItem('hoodie_changedObjectIds')
})
}

module.exports = Store

0 comments on commit 3453aaf

Please sign in to comment.