@@ -11,7 +11,7 @@ import capitalize from 'lodash/capitalize';
11
11
import Immutable from 'immutable' ;
12
12
import isArray from 'lodash/isArray' ;
13
13
import isUndefined from 'lodash/isUndefined' ;
14
- import namedGroupRegex from './named-group-regexp ' ;
14
+ import namedGroupRegex from './namedGroupRegexp ' ;
15
15
import { selectQuery } from './selectors' ;
16
16
17
17
import {
@@ -61,7 +61,7 @@ export default class ReduxWPAPI {
61
61
} ;
62
62
} ,
63
63
64
- // FIXME provisional method while waiting WP-API/node-wpapi#213
64
+ // FIXME provisional method while WAITING WP-API/node-wpapi#213
65
65
getIndexes ( request ) {
66
66
/* eslint-disable no-param-reassign */
67
67
// Internal mutations inside reduce function
@@ -194,23 +194,23 @@ export default class ReduxWPAPI {
194
194
if ( meta . operation === 'get' ) {
195
195
let cache ;
196
196
let lastCacheUpdate ;
197
- let cachePath ;
197
+ let data ;
198
198
const state = store . getState ( ) . wp ;
199
199
const indexes = this . settings . getIndexes ( request , this . settings ) ;
200
200
const localID = this . getEntityLocalID ( state , meta . aggregator , indexes ) ;
201
201
payload . uid = this . settings . getRequestUID ( request , this . settings ) ;
202
202
payload . page = parseInt ( this . settings . getRequestedPage ( request , this . settings ) || 1 , 10 ) ;
203
203
204
204
if ( localID ) {
205
- cachePath = localID ;
206
- cache = state . getIn ( [ 'entities' , cachePath ] ) ;
205
+ cache = state . getIn ( [ 'entities' , localID ] ) ;
206
+ data = [ localID ] ;
207
207
}
208
208
209
209
if ( cache ) {
210
210
lastCacheUpdate = cache . lastCacheUpdate ;
211
211
} else {
212
- cachePath = [ 'requestsByQuery' , payload . uid ] ;
213
- cache = state . getIn ( [ ... cachePath , payload . page ] ) ;
212
+ cache = state . getIn ( [ 'requestsByQuery' , payload . uid , payload . page ] ) ;
213
+ data = cache . get ( 'data' ) ;
214
214
}
215
215
216
216
if ( cache && ( localID || ( isUndefined ( localID ) && ! cache . get ( 'error' ) ) ) ) {
@@ -222,7 +222,7 @@ export default class ReduxWPAPI {
222
222
uid : payload . uid ,
223
223
page : payload . page ,
224
224
lastCacheUpdate,
225
- cachePath ,
225
+ data ,
226
226
} ,
227
227
} ) ;
228
228
@@ -263,26 +263,28 @@ export default class ReduxWPAPI {
263
263
reducer = ( state = initialReducerState , action ) => {
264
264
switch ( action . type ) {
265
265
case REDUX_WP_API_CACHE_HIT : {
266
- const { cachePath, page, uid } = action . payload ;
267
-
268
- const newState = state . mergeIn ( [ 'requestsByName' , action . meta . name ] , { page, uid } ) ;
269
- if ( newState . getIn ( [ 'requestsByQuery' , uid , page ] ) ) {
270
- return newState ;
271
- }
266
+ const { data, page, uid } = action . payload ;
267
+ let newState = state . mergeIn (
268
+ [ 'requestsByName' , action . meta . name ] ,
269
+ { page, uid }
270
+ ) ;
272
271
273
- return (
274
- newState . mergeIn (
275
- [ 'requestsByQuery' , uid , 1 ] ,
276
- {
272
+ if ( ! newState . getIn ( [ 'requestsByQuery' , uid , page ] ) ) {
273
+ newState = (
274
+ newState
275
+ . mergeIn ( [ 'requestsByQuery' , uid , page ] , {
277
276
status : READY ,
278
277
operation : action . meta . operation ,
279
278
error : false ,
280
279
requestAt : action . payload . lastCacheUpdate ,
281
280
responseAt : action . payload . lastCacheUpdate ,
282
- data : [ cachePath ] ,
283
- }
284
- )
285
- ) ;
281
+ } )
282
+ . setIn ( [ 'requestsByQuery' , uid , 1 , 'data' ] , data )
283
+ ) ;
284
+ }
285
+
286
+
287
+ return newState ;
286
288
}
287
289
288
290
case REDUX_WP_API_REQUEST : {
0 commit comments