Skip to content

Commit 434cbb6

Browse files
author
Nick Colley
committed
fix: .clear() removed in favour of .reset()
BREAKING CHANGE: `store.clear()` method has been removed in favor of `store.reset(options)`
1 parent c0baf76 commit 434cbb6

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,21 @@ function Store (dbName, options) {
6161

6262
var api = merge(
6363
scoped.bind(null, state, storeApi),
64-
storeApi,
64+
{
65+
db: storeApi.db,
66+
add: storeApi.add,
67+
find: storeApi.find,
68+
findAll: storeApi.findAll,
69+
findOrAdd: storeApi.findOrAdd,
70+
update: storeApi.update,
71+
updateOrAdd: storeApi.updateOrAdd,
72+
updateAll: storeApi.updateAll,
73+
remove: storeApi.remove,
74+
removeAll: storeApi.removeAll,
75+
on: storeApi.on,
76+
one: storeApi.one,
77+
off: storeApi.off
78+
},
6579
{
6680
hasLocalChanges: hasLocalChanges,
6781
push: syncWrapper.bind(syncApi, 'push'),
@@ -73,7 +87,7 @@ function Store (dbName, options) {
7387
}
7488
)
7589

76-
api.reset = require('./lib/reset').bind(null, dbName, CustomPouchDB, state, api, emitter, remote, ajaxOptions, PouchDB)
90+
api.reset = require('./lib/reset').bind(null, dbName, CustomPouchDB, state, api, storeApi.clear, emitter, remote, ajaxOptions, PouchDB)
7791

7892
subscribeToSyncEvents(syncApi, emitter)
7993
subscribeToInternalEvents(emitter)

lib/reset.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var subscribeToSyncEvents = require('./subscribe-to-sync-events')
66
var syncWrapper = require('./sync-wrapper')
77
var scoped = require('./scoped/')
88

9-
function reset (dbName, CustomPouchDB, state, api, emitter, remote, ajaxOptions, PouchDB, options) {
9+
function reset (dbName, CustomPouchDB, state, api, clear, emitter, remote, ajaxOptions, PouchDB, options) {
1010
if (options) {
1111
if (options.name) {
1212
dbName = options.name
@@ -19,7 +19,7 @@ function reset (dbName, CustomPouchDB, state, api, emitter, remote, ajaxOptions,
1919
CustomPouchDB = PouchDB.defaults(options)
2020
}
2121

22-
return api.clear()
22+
return clear()
2323

2424
.then(function () {
2525
var newDB = new CustomPouchDB(dbName)
@@ -31,7 +31,21 @@ function reset (dbName, CustomPouchDB, state, api, emitter, remote, ajaxOptions,
3131
return merge(
3232
api,
3333
scoped.bind(null, state, storeApi),
34-
storeApi,
34+
{
35+
db: storeApi.db,
36+
add: storeApi.add,
37+
find: storeApi.find,
38+
findAll: storeApi.findAll,
39+
findOrAdd: storeApi.findOrAdd,
40+
update: storeApi.update,
41+
updateOrAdd: storeApi.updateOrAdd,
42+
updateAll: storeApi.updateAll,
43+
remove: storeApi.remove,
44+
removeAll: storeApi.removeAll,
45+
on: storeApi.on,
46+
one: storeApi.one,
47+
off: storeApi.off
48+
},
3549
{
3650
push: syncWrapper.bind(syncApi, 'push'),
3751
pull: syncWrapper.bind(syncApi, 'pull'),

tests/specs/constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function cleanupDb (store, t) {
135135
test('Store api exports', function (t) {
136136
var store = new Store('test-db', merge({remote: 'test-db-remote'}, options))
137137

138-
t.is(store.clear, 'undefined', 'store doesnt expose clear method')
138+
t.is(typeof store.clear, 'undefined', 'store doesnt expose clear method')
139139

140140
t.end()
141141
})

tests/specs/has-local-changes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('.hasLocalChanges(filter)', function (t) {
4949
t.is(store.hasLocalChanges('test1'), true, 'returns "true" with id filter')
5050
t.is(store.hasLocalChanges({id: 'test2'}), true, 'returns "true" to with object filter')
5151

52-
return store.clear()
52+
return store.reset()
5353
})
5454

5555
.then(function () {

0 commit comments

Comments
 (0)