Skip to content

Commit 1f814da

Browse files
committed
#15 - Expose a destroy method to allow for global teardown
1 parent 3407c3f commit 1f814da

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/scripts/containers/AppContainer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ const AppContainer = Container({
116116
*/
117117
handleBlur () {
118118
// Should the container require to do anything in particular here
119+
},
120+
121+
/**
122+
* Destroy the entire Typeset instance
123+
* @func destroy
124+
*/
125+
destroy () {
126+
const { mediator } = this;
127+
mediator.emit('app:destroy');
119128
}
120129
}
121130
});

src/scripts/core/Container.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ const Container = function Container(containerObj) {
166166
return {
167167
setMediatorParent (parentMediator) {
168168
mediator.setParent(parentMediator);
169-
}
169+
},
170+
171+
destroy: boundMethods.destroy
170172
};
171173
}
172174
};

test/server/html/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@
6161
</head>
6262
<body>
6363
<div class='header'>
64-
<h1>Typester test server</h1>
64+
<h1>
65+
Typester test server
66+
<button class='destroy-btn'>Destroy</button>
67+
</h1>
6568
<div class='inspector-tools'>
6669
<a class='inspect-content' data-target-inspector='content'>Inspect Content</a>
6770
<a class='inspect-canvas' data-target-inspector='canvas'>Inspect Canvas</a>
@@ -114,7 +117,7 @@ <h1>Typester test server</h1>
114117
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
115118
<script>
116119
const contentEditable = document.getElementById('content-editable');
117-
new Typester({
120+
const typesterInstance = new Typester({
118121
el: contentEditable,
119122
configs: {
120123
// toolbar: {
@@ -130,6 +133,7 @@ <h1>Typester test server</h1>
130133
}
131134
}
132135
});
136+
console.log(typesterInstance);
133137
</script>
134138

135139
<script>
@@ -138,6 +142,7 @@ <h1>Typester test server</h1>
138142

139143
const contentInspector = document.getElementById('content-inspector');
140144
const inspectorTools = document.querySelectorAll('.inspector-tools a');
145+
const destroyBtn = document.querySelector('.destroy-btn');
141146

142147
inspectorTools.forEach(function (inspectorTool, index) {
143148
if (index === 0) {
@@ -230,7 +235,10 @@ <h1>Typester test server</h1>
230235
editorObserver.observe(contentEditable, observerConfig);
231236
canvasObserver.observe(document.querySelector('.typester-canvas'), observerConfig);
232237
updateInspector();
233-
// requestAnimationFrame(updateInspector);
238+
239+
destroyBtn.addEventListener('click', function () {
240+
typesterInstance.destroy();
241+
});
234242
})();
235243
</script>
236244
</body>

0 commit comments

Comments
 (0)