@@ -21,7 +21,7 @@ function deserialiseArray (obj) {
2121/**
2222 * Deserialises a JSON-API response
2323 *
24- * @param {Object } obj The response
24+ * @param {Object } response The raw JSON:API response object
2525 * @returns {Object } The deserialised response
2626 *
2727 * @example <caption>Deserialise with a basic data object</caption>
@@ -54,21 +54,19 @@ function deserialiseArray (obj) {
5454 * ]
5555 * }) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } }
5656 */
57- export function deserialise ( obj ) {
58- if ( ! obj ) return
57+ export function deserialise ( response ) {
58+ if ( ! response ) return
5959
6060 // Collection of resources
61- // Note: constructor is currently faster than isArray()
62- // http://jsben.ch/QgYAV
63- if ( obj . data && obj . data . constructor === Array ) obj = deserialiseArray ( obj )
61+ if ( response . data && Array . isArray ( response . data ) ) response = deserialiseArray ( response )
6462 // Single resource with included relationships
65- else if ( obj . included ) obj . data = linkRelationships ( obj . data , obj . included )
66- else if ( obj . data && obj . data . constructor === Object ) obj . data = linkRelationships ( obj . data )
63+ else if ( response . included ) response . data = linkRelationships ( response . data , response . included )
64+ else if ( response . data && response . data . constructor === Object ) response . data = linkRelationships ( response . data )
6765
68- delete obj . included
66+ delete response . included
6967
7068 // Move attributes to the parent object
71- if ( obj . data && obj . data . attributes ) obj . data = deattribute ( obj . data )
69+ if ( response . data && response . data . attributes ) response . data = deattribute ( response . data )
7270
73- return obj
71+ return response
7472}
0 commit comments