From bd628e1e9e7b8885574c6c651010e5916c27ba3b Mon Sep 17 00:00:00 2001 From: Richard Doe <richard.doe@rwdit.net> Date: Mon, 18 May 2020 16:37:12 +0100 Subject: [PATCH] Memoize annotation resources --- src/lib/AnnotationList.js | 7 +++++-- src/lib/AnnotationPage.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/AnnotationList.js b/src/lib/AnnotationList.js index 2744d6e9c..701ac5695 100644 --- a/src/lib/AnnotationList.js +++ b/src/lib/AnnotationList.js @@ -21,8 +21,11 @@ export default class AnnotationList { /** */ get resources() { - if (!this.json || !this.json.resources) return []; + this._resources = this._resources || (() => { // eslint-disable-line no-underscore-dangle + if (!this.json || !this.json.resources) return []; - return flatten([this.json.resources]).map(resource => new AnnotationResource(resource)); + return flatten([this.json.resources]).map(resource => new AnnotationResource(resource)); + })(); + return this._resources; // eslint-disable-line no-underscore-dangle } } diff --git a/src/lib/AnnotationPage.js b/src/lib/AnnotationPage.js index 6eb0d9285..d83ac072d 100644 --- a/src/lib/AnnotationPage.js +++ b/src/lib/AnnotationPage.js @@ -24,9 +24,12 @@ export default class AnnotationPage { /** */ get items() { - if (!this.json || !this.json.items) return []; + this._items = this._items || (() => { // eslint-disable-line no-underscore-dangle + if (!this.json || !this.json.items) return []; - return flatten([this.json.items]).map(resource => new AnnotationItem(resource)); + return flatten([this.json.items]).map(resource => new AnnotationItem(resource)); + })(); + return this._items; // eslint-disable-line no-underscore-dangle } /** -- GitLab