Switch from attribute+observer to bubbling events for comms

This commit is contained in:
Ian Gulliver
2019-07-16 16:05:29 +00:00
parent 329727ff9e
commit ccf4299d5a
3 changed files with 25 additions and 14 deletions

View File

@@ -46,9 +46,13 @@ class Architype {
}
this.observer_ = new MutationObserver(() => { this.onChange(); });
this.observer2_ = new MutationObserver(() => { this.snapshot(false); });
this.observe();
this.container_.addEventListener('renderRequest',
() => { this.onRenderRequest(); });
this.container_.addEventListener('snapshotRequest',
() => { this.onSnapshotRequest(); });
this.render();
this.snapshot(true);
}
@@ -62,14 +66,6 @@ class Architype {
observe() {
this.observer_.observe(this.editorElem_, {
attributes: true,
attributeFilter: ['data-arch-render'],
childList: true,
subtree: true,
});
this.observer2_.observe(this.editorElem_, {
attributes: true,
attributeFilter: ['data-arch-snapshot'],
childList: true,
subtree: true,
});
@@ -77,7 +73,6 @@ class Architype {
unobserve() {
this.observer_.disconnect();
this.observer2_.disconnect();
}
serialize() {
@@ -168,11 +163,20 @@ class Architype {
this.first_ = (e.state == 'first');
}
onChange() {
onRenderRequest() {
++this.generation_;
this.render();
}
onSnapshotRequest() {
this.snapshot(false);
}
onChange() {
this.onRenderRequest();
this.onSnapshotRequest();
}
snapshot(first) {
this.serialized_ = this.serialize();
this.serializedStr_ = JSON.stringify(this.serialized_);