Skip to content

Commit 1288080

Browse files
committed
Better handling of includes for 'clearOnUpdate'
- Includes must come after 'get' has cleared the store - Includes must use mergeRecords, or they too will clear the store
1 parent 174898c commit 1288080

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"babel-polyfill": "^6.26.0",
1818
"chai": "^4.3.4",
1919
"chai-as-promised": "^7.1.1",
20-
"chromedriver": "91",
20+
"chromedriver": "^93",
2121
"concurrently": "^6.2.1",
2222
"core-js": "^3.16.1",
2323
"eslint": "^7.32.0",
@@ -49,7 +49,7 @@
4949
"vuex": "^4.0.0"
5050
},
5151
"name": "jsonapi-vuex",
52-
"version": "5.3.0",
52+
"version": "5.4.0",
5353
"description": "Access restructured JSONAPI data from a Vuex Store.",
5454
"keywords": [
5555
"vue",

src/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ const actions = (api, conf) => {
8585
config['data'] = config['data'] || {}
8686
merge(apiConf, config)
8787
return api(apiConf).then((results) => {
88-
utils.processIncludedRecords(context, results)
8988
let resData = utils.jsonapiToNorm(results.data.data)
9089
context.commit('addRecords', resData)
9190
if (conf.clearOnUpdate) {
@@ -97,6 +96,7 @@ const actions = (api, conf) => {
9796
}
9897
context.commit('clearRecords', record)
9998
}
99+
utils.processIncludedRecords(context, results)
100100
resData = utils.checkAndFollowRelationships(context.state, context.getters, resData)
101101
resData = utils.preserveJSON(resData, results.data)
102102
return resData

src/lib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ const Utils = class {
500500
processIncludedRecords(context, results) {
501501
for (let item of get(results, ['data', 'included'], [])) {
502502
const includedItem = this.jsonapiToNormItem(item)
503-
context.commit('addRecords', includedItem)
503+
context.commit('mergeRecords', includedItem)
504504
}
505505
}
506506

tests/unit/actions/get.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ describe('get', function () {
114114
// for a real API call, would need axios include params here
115115
await jsonapiModule.actions.get(stubContext, normWidget1)
116116

117-
expect(stubContext.commit).to.have.been.calledWith('addRecords', normWidget2)
118-
expect(stubContext.commit).to.have.been.calledWith('addRecords', normMachine1)
117+
expect(stubContext.commit).to.have.been.calledWith('mergeRecords', normWidget2)
118+
expect(stubContext.commit).to.have.been.calledWith('mergeRecords', normMachine1)
119119
})
120120

121121
it('should return normalized data with expanded rels (single item)', async function () {

tests/unit/jsonapi-vuex.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('jsonapi-vuex tests', function () {
308308
it('should process included records', function () {
309309
jsonWidget1['included'] = [jsonWidget2]
310310
utils.processIncludedRecords(stubContext, { data: jsonWidget1 })
311-
expect(stubContext.commit).to.have.been.calledWith('addRecords')
311+
expect(stubContext.commit).to.have.been.calledWith('mergeRecords')
312312
})
313313
})
314314

yarn.lock

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,13 @@ axios@^0.21.1:
22292229
dependencies:
22302230
follow-redirects "^1.10.0"
22312231

2232+
axios@^0.21.2:
2233+
version "0.21.4"
2234+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
2235+
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
2236+
dependencies:
2237+
follow-redirects "^1.14.0"
2238+
22322239
babel-eslint@^10.1.0:
22332240
version "10.1.0"
22342241
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
@@ -2879,13 +2886,13 @@ chrome-trace-event@^1.0.2:
28792886
resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz#1015eced4741e15d06664a957dbbf50d041e26ac"
28802887
integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==
28812888

2882-
chromedriver@91:
2883-
version "91.0.1"
2884-
resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-91.0.1.tgz#4d70a569901e356c978a41de3019c464f2a8ebd0"
2885-
integrity sha512-9LktpHiUxM4UWUsr+jI1K1YKx2GENt6BKKJ2mibPj1Wc6ODzX/3fFIlr8CZ4Ftuyga+dHTTbAyPWKwKvybEbKA==
2889+
chromedriver@^93:
2890+
version "93.0.1"
2891+
resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-93.0.1.tgz#3ed1f7baa98a754fc1788c42ac8e4bb1ab27db32"
2892+
integrity sha512-KDzbW34CvQLF5aTkm3b5VdlTrvdIt4wEpCzT2p4XJIQWQZEPco5pNce7Lu9UqZQGkhQ4mpZt4Ky6NKVyIS2N8A==
28862893
dependencies:
28872894
"@testim/chrome-version" "^1.0.7"
2888-
axios "^0.21.1"
2895+
axios "^0.21.2"
28892896
del "^6.0.0"
28902897
extract-zip "^2.0.1"
28912898
https-proxy-agent "^5.0.0"
@@ -4942,6 +4949,11 @@ follow-redirects@^1.0.0, follow-redirects@^1.10.0:
49424949
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43"
49434950
integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==
49444951

4952+
follow-redirects@^1.14.0:
4953+
version "1.14.4"
4954+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
4955+
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==
4956+
49454957
for-in@^1.0.2:
49464958
version "1.0.2"
49474959
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"

0 commit comments

Comments
 (0)