File tree Expand file tree Collapse file tree 3 files changed +8
-15
lines changed Expand file tree Collapse file tree 3 files changed +8
-15
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " jsonapi-vuex" ,
3- "version" : " 5.11.1 " ,
3+ "version" : " 5.12.0 " ,
44 "description" : " Access restructured JSONAPI data from a Vuex Store." ,
55 "author" : " Matthew Richardson <M.Richardson@ed.ac.uk>" ,
66 "scripts" : {
Original file line number Diff line number Diff line change 55 * @memberof module:jsonapi-vuex.jsonapiModule
66 */
77
8- import get from 'lodash/get'
98import { utils } from './jsonapi-vuex'
109
1110export default ( ) => {
@@ -59,21 +58,13 @@ export default () => {
5958 utils . updateRecords ( state , records , true )
6059 } ,
6160 /**
62- * Delete all records from the store for a given type
61+ * Delete all records from the store (of a given type) other than those included in a given record
6362 * @memberof module:jsonapi-vuex.jsonapiModule.mutations
6463 * @param {object } state - The Vuex state object
6564 * @param {object } records - A record with type set.
6665 */
6766 clearRecords : ( state , records ) => {
68- const newRecords = utils . normToStore ( records )
69- for ( let [ type , item ] of Object . entries ( newRecords ) ) {
70- const storeRecords = get ( state , [ type ] , { } )
71- for ( let id of Object . keys ( storeRecords ) ) {
72- if ( ! utils . hasProperty ( item , id ) ) {
73- delete state [ type ] [ id ]
74- }
75- }
76- }
67+ Object . assign ( state , utils . normToStore ( records ) )
7768 } ,
7869 }
7970}
Original file line number Diff line number Diff line change @@ -205,10 +205,12 @@ describe('jsonapi-vuex tests', function () {
205205 describe ( 'clearRecords' , function ( ) {
206206 it ( 'should remove records from the store not in the response (clearOnUpdate)' , function ( ) {
207207 const { clearRecords } = jm . mutations
208- const state = { widget : { 4 : { foo : 4 } } }
208+ const state = { widget : { 1 : { } , 999 : { } } }
209209 clearRecords ( state , normRecord )
210- // '4' not in storeRecord, so should no longer be present in state
211- expect ( state [ 'widget' ] ) . to . not . have . property ( '4' )
210+ // '1' is in normRecord, so should still be present in state
211+ expect ( state [ 'widget' ] ) . to . have . property ( '1' )
212+ // '999' not in normRecord, so should no longer be present in state
213+ expect ( state [ 'widget' ] ) . to . not . have . property ( '999' )
212214 } )
213215 } )
214216 } ) // mutations
You can’t perform that action at this time.
0 commit comments