[Fixed Position] Begin adding element proxy classes

Begin adding proxy classes to allow the toolbar to interact with
elements in a fixed position view, WTD-879.
This commit is contained in:
Victor Woeltjen 2015-02-18 19:26:06 -08:00
parent 466a169562
commit f24f62dedc
4 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,26 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Utility function for creating getter-setter functions,
* since these are frequently useful for element proxies.
* @constructor
* @param {Object} object the object to get/set values upon
* @param {string} key the property to get/set
*/
function Accessor(object, key) {
return function (value) {
if (arguments.length > 0) {
object[key] = value;
}
return value;
};
}
return Accessor;
}
);

View File

@ -0,0 +1,12 @@
/*global define*/
define(
['./TelemetryProxy'],
function (TelemetryProxy) {
"use strict";
return {
"fixed.telemetry": TelemetryProxy
};
}
);

View File

@ -0,0 +1,35 @@
/*global define*/
define(
['./Accessor'],
function (Accessor) {
"use strict";
/**
* Abstract superclass for other classes which provide useful
* interfaces upon an elements in a fixed position view.
* This handles the generic operations (e.g. remove) so that
* subclasses only need to implement element-specific behaviors.
* @constructor
* @param element the telemetry element
* @param index the element's index within its array
* @param {Array} elements the full array of elements
*/
function ElementProxy(element, index, elements) {
return {
x: new Accessor(element, 'x'),
y: new Accessor(element, 'y'),
z: new Accessor(element, 'z'),
width: new Accessor(element, 'width'),
height: new Accessor(element, 'height'),
remove: function () {
if (elements[index] === element) {
elements.splice(index, 1);
}
}
};
}
return ElementProxy;
}
);

View File

@ -0,0 +1,21 @@
/*global define*/
define(
['./ElementProxy'],
function (ElementProxy) {
'use strict';
/**
*
*/
function TelemetryProxy(element, index, elements) {
var proxy = new ElementProxy(element, index, elements);
proxy.id = element.id;
return proxy;
}
return TelemetryProxy;
}
);