Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
for (let key in this.widget_views) {
if(this.widget_views.hasOwnProperty(key)) {
// Ugly, this should be properly done
let [row, col] = String(key).split(',').map(x => parseInt(x));
let widget_view = this.widget_views[key];
if(data[row][col] && data[row][col].value && data[row][col].value.cid == widget_view.model.cid) {
// good, the previous widget_view should be reused
} else {
// we have a leftover view from the previous run
widget_view.remove();
}
}
}
this.widget_views = await widgets.resolvePromisesDict(widget_view_promises)
},
async _build_table() {
async setup() {
// Create control widgets
return resolvePromisesDict({
buttons: Promise.all(this._createButtons()),
side_buttons: Promise.all(this._createSideButtons()),
rotary_encoders: Promise.all(this._createRotaryEncoders()),
rotary_buttons: Promise.all(this._createRotaryButtons()),
faders: Promise.all(this._createFaders())
});
}
}
}
// 2. Make hash based on the controlValues
let hash = this.hash_fn(controlValues);
// 3. Update affected widgets
const outputValue = outputOnChangeData["values"][hash];
if (outputValue !== undefined) {
const key = this.getWidgetValueKey(outputModel["_model_name"]);
state["state"][outputId]["state"][key] = outputValue;
// If its an OutputModel clear the state
// This avoids objects being outputed multiple times
// based on this.clear_state()
await resolvePromisesDict(this._models).then((models) => {
Object.keys(models).forEach((id) => {
let model = models[id];
if (model.name == "OutputModel") {
models[id].close();
this._models[model.model_id] = null;
}
});
});
await this.set_state(state);
if (outputModel["_model_name"] == "OuptuModel") {
this.renderWidget(outputId);
}
}
});
}
set_scale_views: function() {
// first, if this.scales was already defined, unregister from the
// old ones.
for (var key in this.scales) {
this.stopListening(this.scales[key]);
}
var scale_models = this.model.get("scales");
var that = this;
var scale_promises = {};
_.each(scale_models, function(model, key) {
scale_promises[key] = that.create_child_view(model);
});
return widgets.resolvePromisesDict(scale_promises).then(function(scales) {
that.scales = scales;
that.set_positional_scales();
that.initialize_additional_scales();
that.set_ranges();
that.trigger("mark_scales_updated");
});
},
update_scales() {
const scales = this.model.get("scales");
const that = this;
this.scale_promises = widgets.resolvePromisesDict({
"x": Promise.all((scales.x || []).map(function(model : widgets.WidgetModel) {
return that.create_child_view(model);
})),
"y": Promise.all((scales.y || []).map(function(model : widgets.WidgetModel) {
return that.create_child_view(model);
})),
});
widgets.resolvePromisesDict(this.scale_promises)
.then(_.bind(this.set_ranges, this));
}
update_scales() {
const scales = this.model.get("scales");
const that = this;
this.scale_promises = widgets.resolvePromisesDict({
"x": Promise.all((scales.x || []).map(function(model : widgets.WidgetModel) {
return that.create_child_view(model);
})),
"y": Promise.all((scales.y || []).map(function(model : widgets.WidgetModel) {
return that.create_child_view(model);
})),
});
widgets.resolvePromisesDict(this.scale_promises)
.then(_.bind(this.set_ranges, this));
}
update_bounds() {
return widgets.resolvePromisesDict(this.views).then(views => {
var bounds = {
north: -90,
south: 90,
east: -180,
west: 180
};
Object.keys(views).reduce(function(bnds, key) {
var obj = views[key].obj;
if (obj) {
var view_bounds = obj.getBounds();
bnds.north = Math.max(bnds.north, view_bounds.getNorth());
bnds.south = Math.min(bnds.south, view_bounds.getSouth());
bnds.east = Math.max(bnds.east, view_bounds.getEast());
bnds.west = Math.min(bnds.west, view_bounds.getWest());
}
return bnds;
create_scale_views() {
for (let key in this.scales) {
this.stopListening(this.scales[key]);
}
const scale_models = this.model.get("scales");
const that = this;
const scale_promises = {};
_.each(scale_models, function(model : widgets.WidgetModel, key) {
scale_promises[key] = that.create_child_view(model);
});
return widgets.resolvePromisesDict(scale_promises).then(function(d) {
that.scales = d;
that.set_scales();
});
}