now maps to an array of widgets of that type. For most types of
widget, only one instance per team makes sense, so the team.widget
method now complains loudly if it's invoked for a type that has more
than one instance -- client code should never do that. visitWidgets
now visits all widgets of the specified type.
var m_tempateText = {}; // widgets can register tempates to be compiled
var m_template = {}; // compiled templates, from any source
var m_config = mkws.objectInheritingFrom(mkws.config);
var m_tempateText = {}; // widgets can register tempates to be compiled
var m_template = {}; // compiled templates, from any source
var m_config = mkws.objectInheritingFrom(mkws.config);
- var m_widgets = {}; // Maps widget-type to object
+ var m_widgets = {}; // Maps widget-type to array of widget objects
that.toString = function() { return '[Team ' + teamName + ']'; };
that.toString = function() { return '[Team ' + teamName + ']'; };
that.addWidget = function(w) {
that.addWidget = function(w) {
- if (!m_widgets[w.type]) {
- m_widgets[w.type] = w;
- //log("Added '" + w.type + "' widget to team '" + m_teamName + "'");
- } else if (typeof(m_widgets[w.type]) !== 'number') {
- m_widgets[w.type] = 2;
- //log("Added duplicate '" + w.type + "' widget to team '" + m_teamName + "'");
+ if (m_widgets[w.type] === undefined) {
+ m_widgets[w.type] = [ w ];
+ log("Added '" + w.type + "' widget to team '" + m_teamName + "'");
- m_widgets[w.type] += 1;
- //log("Added '" + w.type + "' widget #" + m_widgets[w.type] + "' to team '" + m_teamName + "'");
+ m_widgets[w.type].push(w);
+ log("Added '" + w.type + "' widget #" + m_widgets[w.type].length + "' to team '" + m_teamName + "'");
}
}
that.visitWidgets = function(callback) {
for (var type in m_widgets) {
}
}
that.visitWidgets = function(callback) {
for (var type in m_widgets) {
- var res = callback(type, m_widgets[type]);
- if (res !== undefined)
- return res;
+ var list = m_widgets[type];
+ for (var i = 0; i < list.length; i++) {
+ var res = callback(type, list[i]);
+ if (res !== undefined) {
+ return res;
+ }
+ }
}
return undefined;
}
that.widget = function(type) {
}
return undefined;
}
that.widget = function(type) {
- return m_widgets[type];
+ var list = m_widgets[type];
+ if (list.length > 1) {
+ alert("widget('" + type + "') finds " + list.length + " widgets: using first");
+ }
+ return list[0];