1- import localForage from "localforage" ;
1+ import localForage from "localforage"
22
3- import endpoints from './endpoints.json' ;
4- import rootEndpoints from './rootEndpoints.json' ;
5- import { loadResource } from './getter.js' ;
6- import { installSW } from './installSW.js' ;
7- import { Values } from './default .js' ;
3+ import endpoints from './endpoints.json'
4+ import rootEndpoints from './rootEndpoints.json'
5+ import { loadResource } from './getter.js'
6+ import { installSW } from './installSW.js'
7+ import { Config } from './config .js'
88
99export class Pokedex {
1010
1111 constructor ( config ) {
12- this . values = new Values ( config )
12+ this . config = new Config ( config )
1313 this . getConfig = function ( ) {
14- return this . values
14+ return this . config
1515 }
1616
1717 // add to Pokedex.prototype all our endpoint functions
@@ -21,22 +21,22 @@ export class Pokedex {
2121
2222 // if the user has submitted a Name or an ID, return the JSON promise
2323 if ( typeof input === 'number' || typeof input === 'string' ) {
24- return loadResource ( this . values , `${ this . values . versionPath } ${ endpoint [ 1 ] } /${ input } /` ) ;
24+ return loadResource ( this . config , `${ this . config . versionPath } ${ endpoint [ 1 ] } /${ input } /` )
2525 }
2626
2727 // if the user has submitted an Array
2828 // return a new promise which will resolve when all loadResource calls are ended
2929 else if ( typeof input === 'object' ) {
30- return Promise . all ( mapResources ( this . values , endpoint , input ) ) ;
30+ return Promise . all ( mapResources ( this . config , endpoint , input ) )
3131 }
3232 }
3333 }
34- } ) ;
34+ } )
3535
3636 rootEndpoints . forEach ( rootEndpoint => {
3737 this [ rootEndpoint [ 0 ] ] = config => {
38- var limit = this . values . limit
39- var offset = this . values . offset
38+ var limit = this . config . limit
39+ var offset = this . config . offset
4040 if ( config ) {
4141 if ( config . hasOwnProperty ( 'offset' ) ) {
4242 offset = config . offset
@@ -45,32 +45,32 @@ export class Pokedex {
4545 limit = config . limit
4646 }
4747 }
48- return loadResource ( this . values , `${ this . values . versionPath } ${ rootEndpoint [ 1 ] } ?limit=${ limit } &offset=${ offset } ` ) ;
48+ return loadResource ( this . config , `${ this . config . versionPath } ${ rootEndpoint [ 1 ] } ?limit=${ limit } &offset=${ offset } ` )
4949 }
50- } ) ;
50+ } )
5151
5252 localForage . config ( {
5353 name : 'pokeapi-js-wrapper'
54- } ) ;
54+ } )
5555
56- if ( this . values . cacheImages ) {
56+ if ( this . config . cacheImages ) {
5757 installSW ( )
5858 }
5959 }
6060
6161 resource ( path ) {
6262 if ( typeof path === 'string' ) {
63- return loadResource ( this . values , path )
63+ return loadResource ( this . config , path )
6464 } else if ( typeof path === 'object' ) {
65- return Promise . all ( path . map ( p => loadResource ( this . values , p ) ) ) ;
65+ return Promise . all ( path . map ( p => loadResource ( this . config , p ) ) )
6666 } else {
6767 return 'String or Array is required'
6868 }
6969 }
70- } ;
70+ }
7171
72- function mapResources ( values , endpoint , input ) {
72+ function mapResources ( config , endpoint , input ) {
7373 return input . map ( res => {
74- return loadResource ( values , `${ values . versionPath } ${ endpoint [ 1 ] } /${ res } /` ) ;
75- } ) ;
74+ return loadResource ( config , `${ config . versionPath } ${ endpoint [ 1 ] } /${ res } /` )
75+ } )
7676}
0 commit comments