From e2d4e61b477546fb8b57a4fd046a9916faaeab21 Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Thu, 2 Dec 2021 10:25:19 +0100 Subject: [PATCH] loadAnnotations and setAnnotations now both return a Promise that completes after rendering --- public/index.html | 3 ++- src/TextAnnotator.jsx | 3 ++- src/index.jsx | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index 699c003..4810f6f 100644 --- a/public/index.html +++ b/public/index.html @@ -94,7 +94,8 @@

Homer: The Odyssey

relationVocabulary: [ 'isRelated', 'isPartOf', 'isSameAs '] }); - r.loadAnnotations('annotations.w3c.json'); + r.loadAnnotations('annotations.w3c.json') + .then(() => console.log('loaded')); r.on('selectAnnotation', function(a) { console.log('selected', a); diff --git a/src/TextAnnotator.jsx b/src/TextAnnotator.jsx index 02f18d4..d6523ba 100644 --- a/src/TextAnnotator.jsx +++ b/src/TextAnnotator.jsx @@ -307,7 +307,8 @@ export default class TextAnnotator extends Component { this.relationsLayer.clear(); const clones = annotations.map(a => a.clone()); - this.highlighter.init(clones).then(() => + + return this.highlighter.init(clones).then(() => this.relationsLayer.init(clones)); } diff --git a/src/index.jsx b/src/index.jsx index f2b68a9..b846416 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -125,8 +125,7 @@ export class Recogito { loadAnnotations = (url, requestArgs) => fetch(url, requestArgs) .then(response => response.json()).then(annotations => { - this.setAnnotations(annotations); - return annotations; + return this.setAnnotations(annotations).then(() => annotations); }); off = (event, callback) => @@ -146,7 +145,7 @@ export class Recogito { setAnnotations = arg => { const annotations = arg || []; const webannotations = annotations.map(a => new WebAnnotation(a)); - this._app.current.setAnnotations(webannotations); + return this._app.current.setAnnotations(webannotations); } setAuthInfo = authinfo =>