client/notes: fix saving post breaking selection

The problem was with dangling references - the saved post has been
replacing the note collection with entirely new class instances, whereas
the notes control clung onto old references. Now the control detects
such reloads and acts accordingly.
This commit is contained in:
rr- 2016-08-05 22:48:40 +02:00
parent 8e9ddf796f
commit 70a65cc0a3

View file

@ -552,6 +552,7 @@ class PostNotesOverlayControl extends events.EventTarget {
this._createPolygonNode(note);
}
this._hostNode.appendChild(this._svgNode);
this._post.addEventListener('change', e => this._evtPostChange(e));
this._post.notes.addEventListener('remove', e => {
this._deletePolygonNode(e.detail.note);
});
@ -597,6 +598,16 @@ class PostNotesOverlayControl extends events.EventTarget {
return this._hostNode.getBoundingClientRect();
}
_evtPostChange(e) {
while (this._svgNode.childNodes.length) {
this._svgNode.removeChild(this._svgNode.firstChild);
}
this._post = e.detail.post;
for (let note of this._post.notes) {
this._createPolygonNode(note);
}
}
_evtCanvasKeyDown(e) {
this._state.evtCanvasKeyDown(e);
}