Skip to content

Commit e6a91d1

Browse files
Merge pull request #49 from plasticrake/master
setCurrent to create copy when passed Id
2 parents f27daad + 43f1436 commit e6a91d1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/service-module/mutations.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@ export default function makeServiceMutations (service) {
126126
}
127127
},
128128

129-
setCurrent (state, item) {
130-
let id = isObject(item) ? item[idField] : item
129+
setCurrent (state, itemOrId) {
130+
let id
131+
let item
132+
if (isObject(itemOrId)) {
133+
id = itemOrId[idField]
134+
item = itemOrId
135+
} else {
136+
id = itemOrId
137+
item = state.keyedById[id]
138+
}
131139
state.currentId = id
132140
state.copy = _cloneDeep(item)
133141
},

test/service-module/mutations.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ describe('Service Module - Mutations', () => {
247247

248248
assert(state.currentId === 2)
249249
assert.deepEqual(state.copy, item2)
250+
251+
setCurrent(state, item1._id)
252+
253+
assert(state.currentId === 1)
254+
assert.deepEqual(state.copy, item1)
250255
})
251256

252257
it('clearCurrent', () => {

0 commit comments

Comments
 (0)