@twotalltotems/paginatable-list
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "@twotalltotems/paginatable-list", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A self-managed list with pagination.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,5 +5,6 @@ import { createActions, createReducer } from 'reduxsauce'; | ||
export default class PaginationStateManager { | ||
constructor(name, url) { | ||
constructor(name, url, responseStructure = null) { | ||
this.name = name | ||
this.endpointUrl = url | ||
this.responseStructure = responseStructure | ||
this.initialState = { | ||
@@ -71,4 +72,11 @@ items: [] | ||
.then(response => { | ||
dispatch(this.actions.loadMore(response.data)) | ||
successCallback() | ||
if (this.responseStructure) { | ||
var subsetKey = Object.keys(this.responseStructure).filter(key => this.responseStructure[key] === 'items')[0] | ||
if (subsetKey) { | ||
dispatch(this.actions.loadMore(response.data[subsetKey])) | ||
} | ||
} else { | ||
dispatch(this.actions.loadMore(response.data)) | ||
} | ||
successCallback(response.data) | ||
}) | ||
@@ -75,0 +83,0 @@ .catch(error => { |
83634
269