Skip to content

Commit 005118d

Browse files
committed
chore: remove undocumented store.reset behavior
1 parent bf82f2c commit 005118d

File tree

3 files changed

+6
-126
lines changed

3 files changed

+6
-126
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ function Store (dbName, options) {
3232

3333
var db = new options.PouchDB(dbName)
3434
var emitter = new EventEmitter()
35-
var remote = options.remote
36-
var syncApi = db.hoodieSync({remote: remote})
35+
var syncApi = db.hoodieSync(options)
3736
var storeApi = db.hoodieApi({emitter: emitter})
3837

3938
var state = {
@@ -76,7 +75,7 @@ function Store (dbName, options) {
7675
}
7776
)
7877

79-
api.reset = require('./lib/reset').bind(null, dbName, options.PouchDB, state, api, storeApi.clear, emitter, options.remoteBaseUrl, remote)
78+
api.reset = require('./lib/reset').bind(null, dbName, options, state, api, storeApi.clear, emitter)
8079

8180
subscribeToSyncEvents(syncApi, emitter)
8281

lib/reset.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,14 @@ var merge = require('lodash/merge')
44

55
var subscribeToSyncEvents = require('./subscribe-to-sync-events')
66

7-
function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl, remote, options) {
8-
if (options) {
9-
if (options.name) {
10-
dbName = options.name
11-
}
12-
13-
if (options.remote) {
14-
remote = options.remote
15-
} else if (options.name && remoteBaseUrl) {
16-
remote = remoteBaseUrl + '/' + encodeURIComponent(options.name)
17-
}
18-
19-
CustomPouchDB = CustomPouchDB.defaults(options)
20-
}
21-
7+
function reset (dbName, options, state, api, clear, emitter) {
228
return api.disconnect()
239

2410
.then(clear)
2511

2612
.then(function () {
27-
var newDB = new CustomPouchDB(dbName)
28-
var syncApi = newDB.hoodieSync({remote: remote})
13+
var newDB = new options.PouchDB(dbName)
14+
var syncApi = newDB.hoodieSync(options)
2915
var storeApi = newDB.hoodieApi({emitter: emitter})
3016

3117
subscribeToSyncEvents(syncApi, emitter)
@@ -58,6 +44,6 @@ function reset (dbName, CustomPouchDB, state, api, clear, emitter, remoteBaseUrl
5844
}
5945
)
6046

61-
api.reset = reset.bind(null, dbName, CustomPouchDB, state, api, storeApi.clear, emitter, remoteBaseUrl, remote)
47+
api.reset = reset.bind(null, dbName, options, state, api, storeApi.clear, emitter)
6248
})
6349
}

tests/specs/api.js

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var simple = require('simple-mock')
21
var test = require('tape')
32

43
var PouchDB = require('../utils/pouchdb.js')
@@ -125,110 +124,6 @@ test('store.reset creates empty instance of store', function (t) {
125124
.catch(t.fail)
126125
})
127126

128-
test('store.reset creates empty instance of store with new options', function (t) {
129-
t.plan(3)
130-
131-
var store = new Store('test-db-clear', {
132-
PouchDB: PouchDB,
133-
remote: 'test-db-clear'
134-
})
135-
var newOptions = {
136-
name: 'new-test-db-clear',
137-
remote: 'new-test-db-clear'
138-
}
139-
store.on('clear', t.pass.bind(null, '"clear" event emitted'))
140-
141-
// merge in-memory adapter options
142-
store.reset(newOptions)
143-
144-
.then(function () {
145-
return store.findAll()
146-
})
147-
148-
.then(function (result) {
149-
t.deepEqual(result, [], '.findAll() resolves with empty array after .clear()')
150-
t.is(store.db.name, newOptions.name, 'reset store has a new name')
151-
})
152-
153-
.catch(t.fail)
154-
})
155-
156-
test('store.reset creates empty instance of store with new options passed as arguments', function (t) {
157-
t.plan(1)
158-
159-
var reset = require('../../lib/reset')
160-
var clear = function () {
161-
return Promise.resolve()
162-
}
163-
164-
var store = {
165-
disconnect: simple.stub().returnWith(Promise.resolve())
166-
}
167-
168-
reset('new-test-db-clear-arguments', PouchDB, undefined, store, clear, undefined, 'new-test-db-clear-arguments-remote', {})
169-
170-
.then(function () {
171-
t.is(store.db.name, 'new-test-db-clear-arguments', 'reset store has a new name')
172-
})
173-
174-
.catch(t.error)
175-
})
176-
177-
test('store.reset creates empty instance of store with new name and remoteBaseUrl', function (t) {
178-
t.plan(3)
179-
180-
var CustomStore = Store.defaults({
181-
PouchDB: PouchDB,
182-
remoteBaseUrl: 'http://example.com/'
183-
})
184-
var store = new CustomStore('test-db-clear')
185-
var newOptions = {
186-
name: 'new-test-db-clear'
187-
}
188-
store.on('clear', t.pass.bind(null, '"clear" event emitted'))
189-
190-
// merge in-memory adapter options
191-
store.reset(newOptions)
192-
193-
.then(function () {
194-
return store.findAll()
195-
})
196-
197-
.then(function (result) {
198-
t.deepEqual(result, [], '.findAll() resolves with empty array after .clear()')
199-
t.is(store.db.name, 'new-test-db-clear', 'reset store has a new name')
200-
})
201-
202-
.catch(t.fail)
203-
})
204-
205-
test('store.reset creates empty instance of store with new name', function (t) {
206-
t.plan(3)
207-
208-
var store = new Store('test-db-clear', {
209-
PouchDB: PouchDB,
210-
remote: 'test-db-clear'
211-
})
212-
var newOptions = {
213-
name: 'new-test-db-clear'
214-
}
215-
store.on('clear', t.pass.bind(null, '"clear" event emitted'))
216-
217-
// merge in-memory adapter options
218-
store.reset(newOptions)
219-
220-
.then(function () {
221-
return store.findAll()
222-
})
223-
224-
.then(function (result) {
225-
t.deepEqual(result, [], '.findAll() resolves with empty array after .clear()')
226-
t.is(store.db.name, 'new-test-db-clear', 'reset store has a new name')
227-
})
228-
229-
.catch(t.fail)
230-
})
231-
232127
function addEventToArray (array, object) {
233128
if (arguments.length > 2) {
234129
arguments[0].push({

0 commit comments

Comments
 (0)