Skip to content

Commit 581e422

Browse files
committed
Lint database.js
1 parent 31ca65b commit 581e422

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

lib/modules/database.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {NativeModules, NativeEventEmitter} from 'react-native';
55
const FirestackDatabase = NativeModules.FirestackDatabase;
66
const FirestackDatabaseEvt = new NativeEventEmitter(FirestackDatabase);
77

8-
import promisify from '../utils/promisify'
9-
import { Base, ReferenceBase } from './base'
8+
import promisify from '../utils/promisify';
9+
import { Base, ReferenceBase } from './base';
1010

11-
// subscriptionsMap === { path: { modifier: { eventType: [Subscriptions] } } }
12-
let dbSubscriptions = {};
11+
let dbSubscriptions = {}; // { path: { modifier: { eventType: [Subscriptions] } } }
1312

1413
class DataSnapshot {
1514
static key:String;
@@ -36,12 +35,12 @@ class DataSnapshot {
3635

3736
forEach(fn) {
3837
(this.childKeys || [])
39-
.forEach(key => fn(this.value[key]))
38+
.forEach(key => fn(this.value[key]));
4039
}
4140

4241
map(fn) {
4342
let arr = [];
44-
this.forEach(item => arr.push(fn(item)))
43+
this.forEach(item => arr.push(fn(item)));
4544
return arr;
4645
}
4746

@@ -57,9 +56,9 @@ class DatabaseOnDisconnect {
5756

5857
setValue(val) {
5958
const path = this.ref.dbPath();
60-
if (typeof val == 'string') {
59+
if (typeof val === 'string') {
6160
return promisify('onDisconnectSetString', FirestackDatabase)(path, val);
62-
} else if (typeof val == 'object') {
61+
} else if (typeof val === 'object') {
6362
return promisify('onDisconnectSetObject', FirestackDatabase)(path, val);
6463
}
6564
}
@@ -102,7 +101,7 @@ class DatabaseQuery {
102101
}
103102

104103
build() {
105-
const argsSeparator = ':'
104+
const argsSeparator = ':';
106105
let modifiers = [];
107106
if (this.orderBy) {
108107
modifiers.push(this.orderBy.join(argsSeparator));
@@ -114,10 +113,10 @@ class DatabaseQuery {
114113
.forEach(key => {
115114
const filter = this.filters[key];
116115
if (filter) {
117-
const filterArgs = ([key].concat(filter)).join(argsSeparator)
116+
const filterArgs = [key, filter].join(argsSeparator);
118117
modifiers.push(filterArgs);
119118
}
120-
})
119+
});
121120
return modifiers;
122121
}
123122

@@ -180,27 +179,27 @@ class DatabaseRef extends ReferenceBase {
180179
setAt(val) {
181180
const path = this.dbPath();
182181
const value = this._serializeValue(val);
183-
return promisify('set', FirestackDatabase)(path, value)
182+
return promisify('set', FirestackDatabase)(path, value);
184183
}
185184

186185
updateAt(val) {
187186
const path = this.dbPath();
188187
const value = this._serializeValue(val);
189-
return promisify('update', FirestackDatabase)(path, value)
188+
return promisify('update', FirestackDatabase)(path, value);
190189
}
191190

192191
removeAt(key) {
193192
const path = this.dbPath();
194-
return promisify('remove', FirestackDatabase)(path)
193+
return promisify('remove', FirestackDatabase)(path);
195194
}
196195

197196
push(val={}) {
198197
const path = this.dbPath();
199198
const value = this._serializeValue(val);
200199
return promisify('push', FirestackDatabase)(path, value)
201200
.then(({ref}) => {
202-
return new DatabaseRef(this.db, ref.split(separator))
203-
})
201+
return new DatabaseRef(this.db, ref.split(separator));
202+
});
204203
}
205204

206205
on(evt, cb) {
@@ -214,8 +213,8 @@ class DatabaseRef extends ReferenceBase {
214213
this.listeners[evt] = subscriptions;
215214
callback(this);
216215
return subscriptions;
217-
})
218-
});
216+
});
217+
});
219218
}
220219

221220
once(evt='once', cb) {
@@ -229,18 +228,18 @@ class DatabaseRef extends ReferenceBase {
229228
cb(snapshot);
230229
}
231230
return snapshot;
232-
})
231+
});
233232
}
234233

235234
off(evt='', origCB) {
236235
const path = this.dbPath();
237236
const modifiers = this.dbModifiers();
238-
return this.db.off(path, modifiers, evt, origCB)
237+
return this.db.off(path, modifiers, evt, origCB);
239238
}
240239

241240
cleanup() {
242241
let promises = Object.keys(this.listeners)
243-
.map(key => this.off(key))
242+
.map(key => this.off(key));
244243
return Promise.all(promises);
245244
}
246245

@@ -254,8 +253,8 @@ class DatabaseRef extends ReferenceBase {
254253
}
255254
return {
256255
...sum,
257-
[key]: val
258-
}
256+
[key]: val,
257+
};
259258
}, {});
260259
}
261260

@@ -267,8 +266,8 @@ class DatabaseRef extends ReferenceBase {
267266
}
268267
return {
269268
...sum,
270-
[key]: val
271-
}
269+
[key]: val,
270+
};
272271
}, {});
273272
}
274273

@@ -334,8 +333,8 @@ class DatabaseRef extends ReferenceBase {
334333
dbPath() {
335334
let path = this.path;
336335
let pathStr = (path.length > 0 ? path.join('/') : '/');
337-
if (pathStr[0] != '/') {
338-
pathStr = `/${pathStr}`
336+
if (pathStr[0] !== '/') {
337+
pathStr = `/${pathStr}`;
339338
}
340339
return pathStr;
341340
}
@@ -347,7 +346,7 @@ class DatabaseRef extends ReferenceBase {
347346
}
348347

349348
get namespace() {
350-
return `firestack:dbRef`
349+
return 'firestack:dbRef';
351350
}
352351
}
353352

@@ -386,7 +385,7 @@ export class Database extends Base {
386385
promise = this.whenReady(promisify('enablePersistence', FirestackDatabase)(enable));
387386
this.persistenceEnabled = enable;
388387
} else {
389-
promise = this.whenReady(Promise.resolve({status: "Already enabled"}))
388+
promise = this.whenReady(Promise.resolve({status: 'Already enabled'}))
390389
}
391390

392391
return promise;
@@ -456,7 +455,7 @@ export class Database extends Base {
456455
const callback = (ref) => {
457456
const key = this._pathKey(ref.path);
458457
this.refs[key] = ref;
459-
}
458+
};
460459
const subscriptions = [this.successListener, this.errorListener];
461460
return Promise.resolve({callback, subscriptions});
462461
}
@@ -468,7 +467,7 @@ export class Database extends Base {
468467
// Remove subscription
469468
if (dbSubscriptions[pathKey]) {
470469

471-
if (!eventName || eventName === "") {
470+
if (!eventName || eventName === '') {
472471
// remove all listeners for this pathKey
473472
dbSubscriptions[pathKey] = {};
474473
}
@@ -545,4 +544,4 @@ export class Database extends Base {
545544
}
546545
}
547546

548-
export default Database
547+
export default Database;

0 commit comments

Comments
 (0)