generated from Labyricorn/labyricorn-project-template
Step 6.2 Complete — Museum Gallery reference exhibit and Contract 5.3 spec
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Museum Gallery — domain model.
|
||||
*
|
||||
* Deliberately tiny (Step 6.2 brief: "prove the architecture, not to be
|
||||
* visually elaborate"). No DOM, no contract awareness, no transport — a
|
||||
* plain state object with absolute, idempotent setters, exactly the same
|
||||
* shape as Aquarium's and Haunted House's exhibit models.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ARTIFACTS = ['the-orrery', 'star-map', 'meteorite'];
|
||||
var ARTIFACT_LABELS = {
|
||||
'the-orrery': 'The Orrery',
|
||||
'star-map': 'Star Map',
|
||||
meteorite: 'Meteorite Fragment'
|
||||
};
|
||||
|
||||
function Gallery() {
|
||||
this.artifact = ARTIFACTS[0];
|
||||
this.lightingLevel = 0.6;
|
||||
this.rotationSpeed = 0.4;
|
||||
this.labelsEnabled = true;
|
||||
this.spotlightFlashCount = 0;
|
||||
}
|
||||
|
||||
Gallery.prototype.setArtifact = function (value) {
|
||||
if (ARTIFACTS.indexOf(value) === -1 || this.artifact === value) return { changed: false };
|
||||
this.artifact = value;
|
||||
return { changed: true };
|
||||
};
|
||||
|
||||
Gallery.prototype.setLightingLevel = function (value) {
|
||||
if (this.lightingLevel === value) return { changed: false };
|
||||
this.lightingLevel = value;
|
||||
return { changed: true };
|
||||
};
|
||||
|
||||
Gallery.prototype.setRotationSpeed = function (value) {
|
||||
if (this.rotationSpeed === value) return { changed: false };
|
||||
this.rotationSpeed = value;
|
||||
return { changed: true };
|
||||
};
|
||||
|
||||
Gallery.prototype.setLabelsEnabled = function (value) {
|
||||
if (this.labelsEnabled === value) return { changed: false };
|
||||
this.labelsEnabled = value;
|
||||
return { changed: true };
|
||||
};
|
||||
|
||||
Gallery.prototype.read = function (id) {
|
||||
switch (id) {
|
||||
case 'artifact.selected': return this.artifact;
|
||||
case 'lighting.level': return this.lightingLevel;
|
||||
case 'rotation.speed': return this.rotationSpeed;
|
||||
case 'labels.enabled': return this.labelsEnabled;
|
||||
default: return null;
|
||||
}
|
||||
};
|
||||
|
||||
Gallery.prototype.flashSpotlight = function () {
|
||||
this.spotlightFlashCount += 1;
|
||||
return { ok: true };
|
||||
};
|
||||
|
||||
window.MuseumGalleryExhibit = {
|
||||
Gallery: Gallery,
|
||||
ARTIFACTS: ARTIFACTS,
|
||||
ARTIFACT_LABELS: ARTIFACT_LABELS
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user