Skip to content

Commit

Permalink
fixed advanced demo not turning pages by returning fallback value if …
Browse files Browse the repository at this point in the history
…index is invalid in _getDataProp
  • Loading branch information
giacomo-cgn committed Jul 20, 2020
1 parent 1026b91 commit b578341
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/js/BookReader/BookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ export class BookModel {
}

/**
* Helper. Return a prop for a given index. Returns `fallbackValue` if property not on
* page. Returns undefined if page index is invalid.
* Helper. Return a prop for a given index. Returns `fallbackValue` if index is invalid or
* property not on page.
* @param {PageIndex} index
* @param {keyof PageData} prop
* @param {*} fallbackValue return if property not on the record
Expand All @@ -331,10 +331,7 @@ export class BookModel {
_getDataProp(index, prop, fallbackValue = undefined) {
const dataf = this._getDataFlattened();
const invalidIndex = isNaN(index) || index < 0 || index >= dataf.length;

if (invalidIndex) return undefined;

if ('undefined' == typeof(dataf[index][prop]))
if (invalidIndex || 'undefined' == typeof(dataf[index][prop]))
return fallbackValue;
return dataf[index][prop];
}
Expand Down

0 comments on commit b578341

Please sign in to comment.