Skip to content

Commit 5eaeb0e

Browse files
committed
Lint cleanup
1 parent 78a5b2e commit 5eaeb0e

File tree

4 files changed

+62
-56
lines changed

4 files changed

+62
-56
lines changed

src/service-module/make-model.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ eslint
66
import { FeathersVuexOptions } from './types'
77
import { globalModels, prepareAddModel } from './global-models'
88
import { mergeWithAccessors, checkNamespace, getId } from '../utils'
9-
import _merge from 'lodash/merge'
9+
import _merge from 'lodash/merge'
1010
import _get from 'lodash/get'
1111

1212
// A hack to prevent error with this.constructor.preferUpdate
@@ -105,10 +105,10 @@ export default function makeModel(options: FeathersVuexOptions) {
105105
? store.state[namespace].copiesById
106106
: copiesByIdOnModel
107107

108-
109-
const existingItem = hasValidId && !options.clone
110-
? getFromStore.call(this.constructor, id)
111-
: null
108+
const existingItem =
109+
hasValidId && !options.clone
110+
? getFromStore.call(this.constructor, id)
111+
: null
112112

113113
// If it already exists, update the original and return
114114
if (existingItem) {
@@ -118,12 +118,16 @@ export default function makeModel(options: FeathersVuexOptions) {
118118
}
119119

120120
// If cloning and a clone already exists, update and return the original clone. Only one clone is allowed.
121-
const existingClone = (hasValidId || hasValidTempId) && options.clone
122-
? copiesById[id] || copiesById[tempId]
123-
: null
121+
const existingClone =
122+
(hasValidId || hasValidTempId) && options.clone
123+
? copiesById[id] || copiesById[tempId]
124+
: null
124125
if (existingClone) {
125126
// This must be done in a mutation to avoid Vuex errors.
126-
_commit.call(this.constructor, 'merge', { dest: existingClone, source: data })
127+
_commit.call(this.constructor, 'merge', {
128+
dest: existingClone,
129+
source: data
130+
})
127131
return existingClone
128132
}
129133

@@ -137,7 +141,8 @@ export default function makeModel(options: FeathersVuexOptions) {
137141

138142
// Setup instanceDefaults
139143
if (instanceDefaults && typeof instanceDefaults === 'function') {
140-
const defaults = instanceDefaults.call(this, data, { models, store }) || data
144+
const defaults =
145+
instanceDefaults.call(this, data, { models, store }) || data
141146
mergeWithAccessors(this, defaults)
142147
}
143148

@@ -152,7 +157,7 @@ export default function makeModel(options: FeathersVuexOptions) {
152157

153158
// Add the item to the store
154159
// Make sure originalData wasn't an empty object.
155-
if (!options.clone && options.commit !== false && store && originalData) {
160+
if (!options.clone && options.commit !== false && store) {
156161
_commit.call(this.constructor, 'addItem', this)
157162
}
158163
return this
@@ -239,7 +244,8 @@ export default function makeModel(options: FeathersVuexOptions) {
239244
if (this.__isClone) {
240245
throw new Error('You cannot clone a copy')
241246
}
242-
const id = getId(this, idField) != null ? getId(this, idField) : this[tempIdField]
247+
const id =
248+
getId(this, idField) != null ? getId(this, idField) : this[tempIdField]
243249
return this._clone(id)
244250
}
245251

@@ -264,7 +270,10 @@ export default function makeModel(options: FeathersVuexOptions) {
264270
.constructor as typeof BaseModel
265271

266272
if (this.__isClone) {
267-
const id = getId(this, idField) != null ? getId(this, idField) : this[tempIdField]
273+
const id =
274+
getId(this, idField) != null
275+
? getId(this, idField)
276+
: this[tempIdField]
268277
_commit.call(this.constructor, 'resetCopy', id)
269278
return this
270279
} else {
@@ -279,7 +288,10 @@ export default function makeModel(options: FeathersVuexOptions) {
279288
const { idField, tempIdField, _commit, _getters } = this
280289
.constructor as typeof BaseModel
281290
if (this.__isClone) {
282-
const id = getId(this, idField) != null ? getId(this, idField) : this[tempIdField]
291+
const id =
292+
getId(this, idField) != null
293+
? getId(this, idField)
294+
: this[tempIdField]
283295
_commit.call(this.constructor, 'commitCopy', id)
284296

285297
return _getters.call(this.constructor, 'get', id)
@@ -324,17 +336,11 @@ export default function makeModel(options: FeathersVuexOptions) {
324336

325337
if (id == null) {
326338
const error = new Error(
327-
`Missing ${
328-
idField
329-
} property. You must create the data before you can patch with this data`
339+
`Missing ${idField} property. You must create the data before you can patch with this data`
330340
)
331341
return Promise.reject(error)
332342
}
333-
return _dispatch.call(this.constructor, 'patch', [
334-
id,
335-
this,
336-
params
337-
])
343+
return _dispatch.call(this.constructor, 'patch', [id, this, params])
338344
}
339345

340346
/**
@@ -347,17 +353,11 @@ export default function makeModel(options: FeathersVuexOptions) {
347353

348354
if (!id) {
349355
const error = new Error(
350-
`Missing ${
351-
idField
352-
} property. You must create the data before you can update with this data`
356+
`Missing ${idField} property. You must create the data before you can update with this data`
353357
)
354358
return Promise.reject(error)
355359
}
356-
return _dispatch.call(this.constructor, 'update', [
357-
id,
358-
this,
359-
params
360-
])
360+
return _dispatch.call(this.constructor, 'update', [id, this, params])
361361
}
362362

363363
/**
@@ -373,7 +373,7 @@ export default function makeModel(options: FeathersVuexOptions) {
373373
if (params && params.eager) {
374374
_commit.call(this.constructor, 'removeItem', id)
375375
}
376-
return _dispatch.call(this.constructor, 'remove', [ id, params ])
376+
return _dispatch.call(this.constructor, 'remove', [id, params])
377377
} else {
378378
_commit.call(this.constructor, 'removeTemps', [this[tempIdField]])
379379
return Promise.resolve(this)

src/service-module/service-module.mutations.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function makeServiceMutations() {
4040
}
4141

4242
if (isTemp) {
43-
let tempId = item[tempIdField];
43+
let tempId = item[tempIdField]
4444
if (tempId == null) {
4545
tempId = assignTempId(state, item)
4646
}
@@ -90,7 +90,11 @@ export default function makeServiceMutations() {
9090
*
9191
* If there's no Model class, just call updateOriginal on the incoming data.
9292
*/
93-
if (Model && !(item instanceof BaseModel) && !(item instanceof Model)) {
93+
if (
94+
Model &&
95+
!(item instanceof BaseModel) &&
96+
!(item instanceof Model)
97+
) {
9498
item = new Model(item)
9599
}
96100
const original = state.keyedById[id]
@@ -287,12 +291,10 @@ export default function makeServiceMutations() {
287291
const { idField } = state
288292
const ids = data.map(i => i[idField])
289293
const queriedAt = new Date().getTime()
290-
const {
291-
queryId,
292-
queryParams,
293-
pageId,
294-
pageParams
295-
} = getQueryInfo({ qid, query }, response)
294+
const { queryId, queryParams, pageId, pageParams } = getQueryInfo(
295+
{ qid, query },
296+
response
297+
)
296298

297299
if (!state.pagination[qid]) {
298300
Vue.set(state.pagination, qid, {})

src/utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,29 +413,33 @@ export function mergeWithAccessors(
413413

414414
// If the destination is not writable, return. Also ignore blacklisted keys.
415415
// Must explicitly check if writable is false
416-
if (destDesc && destDesc.writable === false || blacklist.includes(key)) {
416+
if ((destDesc && destDesc.writable === false) || blacklist.includes(key)) {
417417
return
418418
}
419419

420420
// Handle Vue observable objects
421421
if (destIsVueObservable || sourceIsVueObservable) {
422422
const isObject = _isObject(source[key])
423-
const isFeathersVuexInstance = isObject && !!(source[key].constructor.modelName || source[key].constructor.namespace)
423+
const isFeathersVuexInstance =
424+
isObject &&
425+
!!(
426+
source[key].constructor.modelName || source[key].constructor.namespace
427+
)
424428
// Do not use fastCopy directly on a feathers-vuex BaseModel instance to keep from breaking reactivity.
425429
if (isObject && !isFeathersVuexInstance) {
426430
try {
427431
const sourceObject = source[key]
428432
dest[key] = fastCopy(source[key])
429433
} catch (err) {
430-
if(!err.message.includes('getter')) {
434+
if (!err.message.includes('getter')) {
431435
throw err
432436
}
433437
}
434438
} else {
435439
try {
436440
dest[key] = source[key]
437-
} catch(err) {
438-
if(!err.message.includes('getter')) {
441+
} catch (err) {
442+
if (!err.message.includes('getter')) {
439443
throw err
440444
}
441445
}

test/service-module/model-instance-defaults.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ function makeContext() {
111111
}
112112
}
113113

114-
describe('Models - Default Values', function () {
114+
describe('Models - Default Values', function() {
115115
beforeEach(() => {
116116
clearModels()
117117
})
118118

119-
it('models default to an empty object when there is no BaseModel.store', function () {
119+
it('models default to an empty object when there is no BaseModel.store', function() {
120120
const { BaseModel } = makeContext()
121121

122122
// Since we're not using this NakedTodo model in a service plugin, it doesn't get
@@ -130,7 +130,7 @@ describe('Models - Default Values', function () {
130130
assert.deepEqual(todo.toJSON(), {}, 'default model is an empty object')
131131
})
132132

133-
it('models have tempIds when there is a store', function () {
133+
it('models have tempIds when there is a store', function() {
134134
const { Todo } = makeContext()
135135
const todo = new Todo()
136136

@@ -143,7 +143,7 @@ describe('Models - Default Values', function () {
143143
)
144144
})
145145

146-
it('adds new instances containing an id to the store', function () {
146+
it('adds new instances containing an id to the store', function() {
147147
const { Todo } = makeContext()
148148

149149
const todo = new Todo({
@@ -156,7 +156,7 @@ describe('Models - Default Values', function () {
156156
assert.deepEqual(todoInStore, todo, 'task was added to the store')
157157
})
158158

159-
it('stores clones in Model.copiesById by default', function () {
159+
it('stores clones in Model.copiesById by default', function() {
160160
const { Todo } = makeContext()
161161
const todo = new Todo({ id: 1, description: 'This is the original' })
162162

@@ -179,7 +179,7 @@ describe('Models - Default Values', function () {
179179
)
180180
})
181181

182-
it('allows instance defaults, including getters and setters', function () {
182+
it('allows instance defaults, including getters and setters', function() {
183183
const { BaseModel } = feathersVuex(feathersClient, {
184184
serverAlias: 'instance-defaults'
185185
})
@@ -215,7 +215,7 @@ describe('Models - Default Values', function () {
215215
assert.equal(car.combined, '1900 Tesla Roadster', 'setters work, too!')
216216
})
217217

218-
it('allows overriding default values in the constructor', function () {
218+
it('allows overriding default values in the constructor', function() {
219219
const { BaseModel } = feathersVuex(feathersClient, {
220220
serverAlias: 'instance-defaults'
221221
})
@@ -239,7 +239,7 @@ describe('Models - Default Values', function () {
239239
assert.equal(car.make, 'Porsche', 'default make set')
240240
})
241241

242-
it(`uses the class defaults if you don't override them in the constructor`, function () {
242+
it(`uses the class defaults if you don't override them in the constructor`, function() {
243243
const { BaseModel } = feathersVuex(feathersClient, {
244244
serverAlias: 'instance-defaults'
245245
})
@@ -283,7 +283,7 @@ describe('Models - Default Values', function () {
283283
assert.deepEqual(person1.location.coordinates, [0, 0], 'defaults won')
284284
})
285285

286-
it('does not share nested objects between instances when you override class defaults in the constructor', function () {
286+
it('does not share nested objects between instances when you override class defaults in the constructor', function() {
287287
const { BaseModel } = feathersVuex(feathersClient, {
288288
serverAlias: 'instance-defaults'
289289
})
@@ -319,7 +319,7 @@ describe('Models - Default Values', function () {
319319
assert(!areSame, 'the locations are different objects')
320320
})
321321

322-
it('allows passing instanceDefaults in the service plugin options', function () {
322+
it('allows passing instanceDefaults in the service plugin options', function() {
323323
const { makeServicePlugin, BaseModel } = feathersVuex(feathersClient, {
324324
serverAlias: 'instance-defaults'
325325
})
@@ -390,7 +390,7 @@ describe('Models - Default Values', function () {
390390
assert.equal(person2.lastName, 'Me', 'lastName was set')
391391
})
392392

393-
it('instanceDefault accessors stay intact with clone and commit', function () {
393+
it('instanceDefault accessors stay intact with clone and commit', function() {
394394
const { makeServicePlugin, BaseModel } = feathersVuex(feathersClient, {
395395
serverAlias: 'instance-defaults'
396396
})
@@ -463,7 +463,7 @@ describe('Models - Default Values', function () {
463463
)
464464
})
465465

466-
it('instanceDefaults in place after patch', async function () {
466+
it('instanceDefaults in place after patch', async function() {
467467
const { Letter, store, lettersService } = makeLetterContext()
468468
let letter = new Letter({ name: 'Garmadon', age: 1025 })
469469

0 commit comments

Comments
 (0)