{"action":"created","issue":{"url":"https://api.github.com/repos/IIIF/mirador/issues/541","labels_url":"https://api.github.com/repos/IIIF/mirador/issues/541/labels{/name}","comments_url":"https://api.github.com/repos/IIIF/mirador/issues/541/comments","events_url":"https://api.github.com/repos/IIIF/mirador/issues/541/events","html_url":"https://github.com/IIIF/mirador/pull/541","id":76439952,"number":541,"title":"Annotations Endpoint is not correctly created for each window","user":{"login":"Wedjaa","id":6388662,"avatar_url":"https://avatars.githubusercontent.com/u/6388662?v=3","gravatar_id":"","url":"https://api.github.com/users/Wedjaa","html_url":"https://github.com/Wedjaa","followers_url":"https://api.github.com/users/Wedjaa/followers","following_url":"https://api.github.com/users/Wedjaa/following{/other_user}","gists_url":"https://api.github.com/users/Wedjaa/gists{/gist_id}","starred_url":"https://api.github.com/users/Wedjaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wedjaa/subscriptions","organizations_url":"https://api.github.com/users/Wedjaa/orgs","repos_url":"https://api.github.com/users/Wedjaa/repos","events_url":"https://api.github.com/users/Wedjaa/events{/privacy}","received_events_url":"https://api.github.com/users/Wedjaa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-14T18:03:42Z","updated_at":"2015-05-14T20:59:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/IIIF/mirador/pulls/541","html_url":"https://github.com/IIIF/mirador/pull/541","diff_url":"https://github.com/IIIF/mirador/pull/541.diff","patch_url":"https://github.com/IIIF/mirador/pull/541.patch"},"body":"When an endpoint module is specified in the configuration the way it is initiated when there are multiple windows open is odd. In the current implementation the is a bit of confusion in the way _this.endpoint and endpoint are checked and populated.\r\n\r\nFor the window instance _this.endpoint is always null when first called, on the other end: endpoint is present if another window, with annotations, has been already initialised.\r\n\r\nWhat happens is that the second window will create a new instance of the endpoint and assign it to the endpoint variable, things get ugly in the deferred, because when the deferred is resolved in that scope, the endpoint from which is getting annotations - via the annotationsList - is no longer the one that is resolving the deferred, but the last one created, possibly with a radically different opinion of what the annotationsList should look like, resulting in a _this.annotationsList that could be different from what is expected.\r\n\r\nIf it doesn't make sense immediately, just try and step in the code and see for different windows what the _this.endpoint and endpoint variables look like.\r\n\r\nThis first part of the fix is still using a single global annotations endpoint, I think it's very efficient. What we do is check for endpoint not being assigned - with a very counterintuitive try/catch - and create only one.  The second call to this function, from another window, will get the same endpoint and use the search function to update the annotationsList of the endpoint.\r\n\r\n**TODO**: as it is the `search` function will overwrite the existing one, I'm not particularly happy with that because it may have some unintended consequences; I have a fix - will push it later - where I change the API contract of the search, so that it accepts  `resolve, reject` parameters and returns the list of annotations in a deferred fashion. Since it breaks the `search` contract I think we must see first who's creating annotations endpoints and what it would mean for them.\r\n "},"comment":{"url":"https://api.github.com/repos/IIIF/mirador/issues/comments/102168061","html_url":"https://github.com/IIIF/mirador/pull/541#issuecomment-102168061","issue_url":"https://api.github.com/repos/IIIF/mirador/issues/541","id":102168061,"user":{"login":"aeschylus","id":145874,"avatar_url":"https://avatars.githubusercontent.com/u/145874?v=3","gravatar_id":"","url":"https://api.github.com/users/aeschylus","html_url":"https://github.com/aeschylus","followers_url":"https://api.github.com/users/aeschylus/followers","following_url":"https://api.github.com/users/aeschylus/following{/other_user}","gists_url":"https://api.github.com/users/aeschylus/gists{/gist_id}","starred_url":"https://api.github.com/users/aeschylus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aeschylus/subscriptions","organizations_url":"https://api.github.com/users/aeschylus/orgs","repos_url":"https://api.github.com/users/aeschylus/repos","events_url":"https://api.github.com/users/aeschylus/events{/privacy}","received_events_url":"https://api.github.com/users/aeschylus/received_events","type":"User","site_admin":false},"created_at":"2015-05-14T20:59:51Z","updated_at":"2015-05-14T20:59:51Z","body":"Yes, the `search method` is another conversation. Someday! The method overwrites the annotation list because the list only pertains to the current manifest page, so it needs to be undone and refetched whenever the use changes pages. It's basically just GET-ing the annotationList for this page from the endpoint. \r\n\r\nOne problem with this is that there is no well-insulated local cache of the annotations, so the request flow is a bit tied up with the display/updating code. There is some effort to extract and abstract this [here](https://github.com/IIIF/manifesto).\r\n\r\nI tried testing this and your other PR locally, and it seems you don't have an endpoint configured, so it would be very strange if any annotations appeared. What are your configuration options? "}}