Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'base' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function monkeypatch() {
// patch Cell.execute and OutputArea.append_error for missing functionality
// find the first code cell
console.log("patching execute");
// create and destroy code cell at end
var nb = Jupyter.notebook;
var ncells = nb.ncells();
var cell = nb.insert_cell_at_index("code", ncells);
var CodeCell = Object.getPrototypeOf(cell);
var OutputArea = Object.getPrototypeOf(cell.output_area);
Jupyter.notebook.delete_cells([ncells]);
if (CodeCell.original_execute) {
// already patched
return;
}
CodeCell.original_execute = CodeCell.execute;
CodeCell.execute = my_execute;
// patch OutputArea.append_error because there is no event for errors
OutputArea.original_append_error = OutputArea.append_error;
SparkMonitor.prototype.startComm = function () {
if (this.comm) {
this.comm.close()
}
console.log('SparkMonitor: Starting Comm with kernel.')
var that = this;
if (Jupyter.notebook.kernel) {
this.comm = Jupyter.notebook.kernel.comm_manager.new_comm('SparkMonitor',
{ 'msgtype': 'openfromfrontend' });
// Register a message handler
this.comm.on_msg($.proxy(that.on_comm_msg, that));
this.comm.on_close($.proxy(that.on_comm_close, that));
}
else {
console.log("SparkMonitor: No communication established, kernel null");
}
}
}
Base.call(this, {}, options);
this.is('Collection');
this.items = {};
this.use(utils.option());
this.use(utils.plugin());
this.init(options || {});
}
/**
* Inherit `Base`
*/
Base.extend(Collection);
/**
* Mixin static methods
*/
plugin.is(Collection);
/**
* Initialize `Collection` defaults
*/
Collection.prototype.init = function(opts) {
debug('initializing', __filename);
// add constructors to the instance
this.define('Item', opts.Item || Collection.Item);
import Dialog from "./_dialog";
import * as utils from "base/utils";
import Component from "base/component";
/*!
* VIZABI DIALOGS
* Reusable dialogs component
*/
//default existing dialogs
const class_active = "vzb-active";
const class_expand_dialog = "vzb-dialog-side";
const Dialogs = Component.extend({
/**
* Initializes the dialogs
* @param config component configuration
* @param context component context (parent)
*/
init(config, context) {
// set properties
this.name = "gapminder-dialogs";
this._curr_dialog_index = 20;
this.model_expects = [{
name: "state",
type: "model"
traversePath: function(path) {
// if there's no path to traverse
if (typeof path === 'undefined' || utils.isArray(path) && path.length == 0) {
return this;
}
// prepare path to array
if (typeof path === 'string') {
path = path.split('.');
}
// check if path is an array
if (!utils.isArray(path)) {
utils.error('Path is wrong type. Path should be a string or array but is ' + typeof path + '.');
return null;
}
// descent to next child to find target object
var currentTarget = path.shift();
if (this[currentTarget] === undefined)
utils.warn('Can\'t find child "' + currentTarget + '" of the model ' + this._name + '.');
else
return this.getModelObject(currentTarget).traversePath(path);
},
traversePath: function(path) {
// if there's no path to traverse
if (typeof path === 'undefined' || utils.isArray(path) && path.length == 0) {
return this;
}
// prepare path to array
if (typeof path === 'string') {
path = path.split('.');
}
// check if path is an array
if (!utils.isArray(path)) {
utils.error('Path is wrong type. Path should be a string or array but is ' + typeof path + '.');
return null;
}
// descent to next child to find target object
var currentTarget = path.shift();
if (this[currentTarget] === undefined)
utils.warn('Can\'t find child "' + currentTarget + '" of the model ' + this._name + '.');
else
return this.getModelObject(currentTarget).traversePath(path);
},
function load_extension() {
console.log("Loading inorder extension");
// when a cell is created we check
events.on("create.Cell", handle_cell_creation);
// when there's an error, mark it and invalidate below
events.on("output_error.InOrderExtension", handle_error);
// when the kernel restarts, reset all state
events.on("kernel_restarting.Kernel", function() {
var cells = Jupyter.notebook.get_cells();
cells.map(function(cell) {
unlock_cell(cell);
cell.element.removeClass("inorder-executed");
});
});
// add our css (!important due to race with cell.selected)
var style = document.createElement("style");
style.type = "text/css";
function load_extension() {
console.log("Loading inorder extension");
// when a cell is created we check
events.on("create.Cell", handle_cell_creation);
// when there's an error, mark it and invalidate below
events.on("output_error.InOrderExtension", handle_error);
// when the kernel restarts, reset all state
events.on("kernel_restarting.Kernel", function() {
var cells = Jupyter.notebook.get_cells();
cells.map(function(cell) {
unlock_cell(cell);
cell.element.removeClass("inorder-executed");
});
});
// add our css (!important due to race with cell.selected)
var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = "div.cell.code_cell.inorder-locked { background-color: #afa}\n" +
"div.cell.code_cell.inorder-locked.inorder-error { background-color: #faa}\n";
document.getElementsByTagName("head")[0].appendChild(style);
// apply patches when the notebook has been loaded
if (!Jupyter.notebook) {
var configmod = require('services/config');
var terminado = require('terminal/js/terminado');
requirejs(['custom/custom'], function() {});
page = new page.Page();
var common_config = new configmod.ConfigSection('common',
{base_url: utils.get_body_data('baseUrl')});
common_config.load();
// Test size: 25x80
var termRowHeight = function(){ return 1.00 * $("#dummy-screen")[0].offsetHeight / 25;};
// 1.02 here arrived at by trial and error to make the spacing look right
var termColWidth = function() { return 1.02 * $("#dummy-screen-rows")[0].offsetWidth / 80;};
var base_url = utils.get_body_data('baseUrl');
var ws_path = utils.get_body_data('wsPath');
var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host
+ base_url + ws_path;
var header = $("#header")[0]
function calculate_size() {
var height = $(window).height() - header.offsetHeight;
var width = $('#terminado-container').width();
var rows = Math.min(1000, Math.max(20, Math.floor(height/termRowHeight())-1));
var cols = Math.min(1000, Math.max(40, Math.floor(width/termColWidth())-1));
console.log("resize to :", rows , 'rows by ', cols, 'columns');
return {rows: rows, cols: cols};
}
page.show_header();
expandCanvas(duration) {
const _this = this.context;
if (!duration) duration = _this.duration;
//d3 extent returns min and max of the input array as [min, max]
const mmX = d3.extent(utils.values(_this.frame.axis_x));
const mmY = d3.extent(utils.values(_this.frame.axis_y));
//protection agains unreasonable min-max results -- abort function
if (!mmX[0] && mmX[0] !== 0 || !mmX[1] && mmX[1] !== 0 || !mmY[0] && mmY[0] !== 0 || !mmY[1] && mmY[1] !== 0) {
return utils.warn("panZoom.expandCanvas: X or Y min/max are broken. Aborting with no action");
}
/*
* Use a range bumped scale to correctly accommodate the range bump
* gutter.
*/
const suggestedFrame = {
x1: _this.xScale(mmX[0]),
y1: _this.yScale(mmY[0]),
x2: _this.xScale(mmX[1]),
y2: _this.yScale(mmY[1])
};
const xBounds = [0, _this.width];
const yBounds = [_this.height, 0];
// Get the current zoom frame based on the current dimensions.
const frame = {