generated from Labyricorn/labyricorn-project-template
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
/*
|
|
* Aquarium — composition root.
|
|
*
|
|
* The last file to load, and the only one that knows about all the others.
|
|
* It builds the exhibit, builds the UI, then hands both to the contract
|
|
* adapter. If the adapter were removed, the first two lines would still
|
|
* produce a complete, working aquarium.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var Shell = window.XZBTShell;
|
|
|
|
var announcer = new Shell.Announcer({
|
|
node: Shell.el('announcement'),
|
|
idleText: 'Tank settled \u2014 awaiting instruction.',
|
|
maxLength: 120
|
|
});
|
|
|
|
var exhibit = new window.AquariumExhibit({
|
|
canvas: Shell.el('tank-canvas'),
|
|
announcer: announcer
|
|
});
|
|
|
|
var ui = new window.AquariumUI(exhibit, announcer);
|
|
|
|
/* Contract layer. Optional by construction: everything above already
|
|
* works without it. */
|
|
var core = window.AquariumContract.create(exhibit, ui);
|
|
|
|
/* Transport layer. Also optional: with no host attached, nothing here
|
|
* ever fires and the exhibit is unchanged. */
|
|
var transport = new window.XZBTHostTransport({
|
|
core: core,
|
|
onMessage: function (request, response) {
|
|
if (response.type === 'hello.result') {
|
|
Shell.setText(Shell.el('contract-status'), 'host attached');
|
|
}
|
|
}
|
|
});
|
|
|
|
exhibit.start();
|
|
|
|
window.addEventListener('resize', function () { exhibit.resize(); });
|
|
|
|
/* Exposed for the conformance harness and for manual console poking. */
|
|
window.__exhibit = {
|
|
core: core,
|
|
exhibit: exhibit,
|
|
ui: ui,
|
|
transport: transport,
|
|
announcer: announcer
|
|
};
|
|
})();
|