Skip to content

Commit 09baf1d

Browse files
authored
Allow simple data modification in clone
This allows a simple one-liner `user.clone({ toggle: true }).save()`
1 parent bef5f3d commit 09baf1d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/service-module/make-base-model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,28 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
256256
/**
257257
* clone the current record using the `createCopy` mutation
258258
*/
259-
public clone() {
259+
public clone(data) {
260260
const { idField, tempIdField } = this.constructor as typeof BaseModel
261261
if (this.__isClone) {
262262
throw new Error('You cannot clone a copy')
263263
}
264264
const id =
265265
getId(this, idField) != null ? getId(this, idField) : this[tempIdField]
266-
return this._clone(id)
266+
return this._clone(id, data)
267267
}
268268

269-
private _clone(id) {
269+
private _clone(id, data) {
270270
const { store, namespace, _commit, _getters } = this
271271
.constructor as typeof BaseModel
272272
const { keepCopiesInStore } = store.state[namespace]
273273

274274
_commit.call(this.constructor, `createCopy`, id)
275275

276276
if (keepCopiesInStore) {
277-
return _getters.call(this.constructor, 'getCopyById', id)
277+
return Object.assign(_getters.call(this.constructor, 'getCopyById', id), data || {})
278278
} else {
279279
// const { copiesById } = this.constructor as typeof BaseModel
280-
return (this.constructor as typeof BaseModel).copiesById[id]
280+
return Object.assign((this.constructor as typeof BaseModel).copiesById[id], data || {})
281281
}
282282
}
283283
/**

0 commit comments

Comments
 (0)